Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # praw is a wrapper for the Reddit API. Makes things simple.
- # re is a regular expression library.
- # os is a library to interface with your OS.
- import praw, re, os
- # Initialize a reddit instance with the useragent user_agent
- r = praw.Reddit(user_agent='fjdlsjafkldjslkfjdsklfajkdslafds')
- # Get a submission stream. This is a pretty fancy object. Replace 'pcmasterrace' with whatever sub. Concatenate multiple subs with a plus: pcmasterrace+gamedeals
- stream = praw.helpers.submission_stream(r, 'pcmasterrace', limit=5, verbosity=-1)
- # Loop through the stream. This only runs when a new submission has happened since the last time it checked ( usually about 2 seconds )
- for submission in stream:
- # Print the name of the author who made the post. Not required.
- print(submission.author)
- # Find all things that look like Steam keys.
- m = re.findall('[a-zA-Z0-9]{4,6}\-[a-zA-Z0-9]{4,6}\-[a-zA-Z0-9]{4,6}', submission.selftext)
- # Print out the matches. Again, not required.
- print m
- # If m is not an empty object then we have something that looks like a key.
- if not m == []:
- # Limit to only one author to prevent being a jackass.
- if str(submission.author) == 'eegras':
- # Output it got a match.
- print "Got a match"
- # open keys.txt, create it if it doesn't exist and truncate it to 0 length
- f = open('keys.txt','w+')
- # write the key to it.
- f.write(m[0])
- # close the file to actually do the write.
- f.close()
- # Run the autohotkey script.
- os.system("getkey.ahk")
- # Delete the text file.
- os.remove('keys.txt')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement