Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.66 KB | None | 0 0
  1. from fake_useragent import UserAgent
  2. import praw, re, os, time
  3.  
  4. def userAgent():
  5.     ua = UserAgent()
  6.     return ua.random
  7.  
  8. def checkRepeat(text):
  9.     count = {}
  10.     returnlist = []
  11.     for char in text:
  12.         if char in count:
  13.             count[char] += 1
  14.         else:
  15.             count[char] = 1
  16.     for key in count:
  17.         if count[key] > 2:
  18.             returnlist.append(key)
  19.     if len(returnlist) > 0:
  20.         return True
  21.     else:
  22.         return False
  23.  
  24. def split(text):
  25.     return text.upper().split()
  26.  
  27. def numDash(var):
  28.     num = 0
  29.     for x in var:
  30.         if x == "-":
  31.             num += 1
  32.     if num == 2 or num == 4:
  33.         return True
  34.     return False
  35.  
  36. def checkList(key,droplist):
  37.     if any(item in key for item in droplist):
  38.         return True
  39.     else:
  40.         return False
  41.  
  42. def findKey(text,droplist):
  43.     matched = []
  44.     allkeys = []
  45.     matchedkeys = []
  46.     verifiedkeys = []
  47.     text = split(text)
  48.     text = [x for x in text if "-" in x]
  49.     for x in text:
  50.         if numDash(x):
  51.             matched.append(x)
  52.         else:
  53.             continue
  54.     keys = [x.replace("-","") for x in matched]
  55.     keys = [x for x in keys if len(x) == 15 or len(x) == 25]
  56.     for x in keys:
  57.         allkeys.append("-".join([x[i:i+5] for i in range(0,len(x),5)]))
  58.     for key in allkeys:
  59.         fullkey = key.replace("-","")
  60.         if not checkRepeat(fullkey):
  61.             verifiedkeys.append(key)
  62.     for x in verifiedkeys:
  63.         chunk = x.split("-")
  64.         for part in chunk:
  65.             if len(chunk) == 5 or len(chunk) == 3:
  66.                 if not "*" in x and not "@" in x:
  67.                     if not checkList(x,droplist):
  68.                         matchedkeys.append(x)
  69.     return matchedkeys
  70.  
  71. def tryKey(key,cache):
  72.     if len(key) > 1:
  73.         for x in key:
  74.             if x not in cache:
  75.                 print(x)
  76.                 os.system("sbka.ahk "+str(x))
  77.                 cache.append(x)
  78.                 time.sleep(1)
  79.     else:
  80.         print(key[0])
  81.         os.system("sbka.ahk "+str(key[0]))
  82.         cache.append(x)
  83.         time.sleep(1)
  84.  
  85. def getPosts(sub,droplist,cache):
  86.     r = praw.Reddit(user_agent=userAgent(),
  87.                      client_id='yK8JCJJrughNRA', client_secret="uOCBiTJyZmq8TJsuoEGv8IEYBNg",
  88.                      username='FouriusVixen', password='latara123')
  89.     subreddit = r.subreddit(sub)
  90.     for submission in subreddit.stream.submissions():
  91.         m = findKey(submission.selftext,droplist)
  92.         if len(m) > 0:
  93.                 tryKey(m,cache)
  94.  
  95.     droplist = ["GABEN", "G4B3N", "SCUM"]
  96.     cache = []
  97.  
  98.     getPosts("test", droplist, cache)
  99.     print("done")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement