Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import config
- import random
- import sqlite3
- import requests
- # import time
- connection= sqlite3.connect('casino.db')
- c = connection.cursor()
- # c.execute("""CREATE TABLE users (
- # username text,
- # balance integer
- # )""")
- #
- # c.execute("""CREATE TABLE comments (
- # id text
- # )""")
- connection.commit()
- def bot_login():
- print ("Logging in...")
- global r
- r = praw.Reddit(username = config.username,
- password = config.password,
- client_id = config.client_id,
- client_secret = config.client_secret,
- user_agent = config.user_agent)
- print ("Logged in!")
- def run():
- for i in range(len(config.terms)):
- search(config.terms[i])
- time.sleep(30)
- def search(term):
- try:
- request = requests.get(('https://api.pushshift.io/reddit/search/comment/?q=!{}&subreddit={}&limit=10').format(term,config.subreddits))
- json = request.json()
- comments = json["data"]
- for comment in comments:
- author = comment["author"]
- body = comment["body"]
- id = comment["id"]
- c.execute(("SELECT * FROM users WHERE username='{}'").format(author))
- if c.fetchone() == None:
- c.execute(("INSERT INTO users VALUES ('{}', 1000)").format(author))
- connection.commit()
- check_comment(author,body,id)
- except Exception as e:
- print(("ERROR: {} in SEARCH function").format(e))
- def check_comment(author,body,id):
- global r
- print("t")
- try:
- comment = r.comment(id=id)
- if "!resetbalance" in body:
- comment.reply(config.resetbalance_text)
- # elif "!checkbalance" in body:
- # comment.reply(config.)
- except Exception as e:
- print(("ERROR: {} in CHECK_COMMENT function").format(e))
- c.execute(("INSERT INTO comments VALUES ('{}')").format(id))
- connection.commit()
- bot_login()
- run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement