SHARE
TWEET

Untitled

dmesticg Dec 31st, 2018 157 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import praw
  2. import config
  3. import random
  4. import sqlite3
  5. import requests
  6. # import time
  7.  
  8. connection= sqlite3.connect('casino.db')
  9. c = connection.cursor()
  10.  
  11. # c.execute("""CREATE TABLE users (
  12. #            username text,
  13. #            balance integer
  14. #            )""")
  15. #
  16. # c.execute("""CREATE TABLE comments (
  17. #             id text
  18. #             )""")
  19.  
  20. connection.commit()
  21.  
  22. def bot_login():
  23.     print ("Logging in...")
  24.     global r
  25.     r = praw.Reddit(username = config.username,
  26.             password = config.password,
  27.             client_id = config.client_id,
  28.             client_secret = config.client_secret,
  29.             user_agent = config.user_agent)
  30.     print ("Logged in!")
  31.  
  32. def run():
  33.     for i in range(len(config.terms)):
  34.         search(config.terms[i])
  35.     time.sleep(30)
  36.  
  37. def search(term):
  38.     try:
  39.         request = requests.get(('https://api.pushshift.io/reddit/search/comment/?q=!{}&subreddit={}&limit=10').format(term,config.subreddits))
  40.         json = request.json()
  41.         comments = json["data"]
  42.         for comment in comments:
  43.             author = comment["author"]
  44.             body = comment["body"]
  45.             id = comment["id"]
  46.             c.execute(("SELECT * FROM users WHERE username='{}'").format(author))
  47.             if c.fetchone() == None:
  48.                 c.execute(("INSERT INTO users VALUES ('{}', 1000)").format(author))
  49.                 connection.commit()
  50.             check_comment(author,body,id)
  51.     except Exception as e:
  52.         print(("ERROR: {} in SEARCH function").format(e))
  53.  
  54. def check_comment(author,body,id):
  55.     global r
  56.     print("t")
  57.     try:
  58.         comment = r.comment(id=id)
  59.         if "!resetbalance" in body:
  60.             comment.reply(config.resetbalance_text)
  61.         # elif "!checkbalance" in body:
  62.         #     comment.reply(config.)
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.     except Exception as e:
  91.         print(("ERROR: {} in CHECK_COMMENT function").format(e))
  92.     c.execute(("INSERT INTO comments VALUES ('{}')").format(id))
  93.     connection.commit()
  94.  
  95.  
  96.  
  97.  
  98. bot_login()
  99. run()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top