Advertisement
Guest User

KeyThief.py

a guest
Feb 18th, 2016
5,656
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.71 KB | None | 0 0
  1. # praw is a wrapper for the Reddit API.  Makes things simple.
  2. # re is a regular expression library.
  3. # os is a library to interface with your OS.
  4. import praw, re, os
  5.  
  6. # Initialize a reddit instance with the useragent user_agent
  7. r = praw.Reddit(user_agent='fjdlsjafkldjslkfjdsklfajkdslafds')
  8.  
  9. # Get a submission stream.  This is a pretty fancy object.  Replace 'pcmasterrace' with whatever sub.  Concatenate multiple subs with a plus: pcmasterrace+gamedeals
  10. stream = praw.helpers.submission_stream(r, 'pcmasterrace', limit=5, verbosity=-1)
  11.  
  12. # Loop through the stream.  This only runs when a new submission has happened since the last time it checked ( usually about 2 seconds )
  13. for submission in stream:
  14.  
  15.     # Print the name of the author who made the post.  Not required.
  16.     print(submission.author)
  17.  
  18.     # Find all things that look like Steam keys.  
  19.     m = re.findall('[a-zA-Z0-9]{4,6}\-[a-zA-Z0-9]{4,6}\-[a-zA-Z0-9]{4,6}', submission.selftext)
  20.  
  21.     # Print out the matches.  Again, not required.
  22.     print m
  23.  
  24.     # If m is not an empty object then we have something that looks like a key.
  25.     if not m == []:
  26.  
  27.         # Limit to only one author to prevent being a jackass.
  28.         if str(submission.author) == 'eegras':
  29.  
  30.             # Output it got a match.
  31.             print "Got a match"
  32.  
  33.             # open keys.txt, create it if it doesn't exist and truncate it to 0 length
  34.             f = open('keys.txt','w+')
  35.  
  36.             # write the key to it.
  37.             f.write(m[0])
  38.  
  39.             # close the file to actually do the write.
  40.             f.close()
  41.  
  42.             # Run the autohotkey script.
  43.             os.system("getkey.ahk")
  44.  
  45.             # Delete the text file.
  46.             os.remove('keys.txt')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement