-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScoreboardAddUser.py
59 lines (51 loc) · 1.51 KB
/
ScoreboardAddUser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#/u/GoldenSights
import praw
import time
import sqlite3
'''USER CONFIGURATION'''
USERNAME = "DecoderBot"
PASSWORD = "copernicus"
USERAGENT = "Regulates posts and assigns flair in /r/Decoders"
#This is a short description of what the bot does. For example "/u/GoldenSights' Newsletter bot"
SUBREDDIT = "Decoders"
#This is the sub or list of subs to scan for new posts. For a single sub, use "sub1". For multiple subreddits, use "sub1+sub2+sub3+..."
'''All done!'''
try:
import bot #This is a file in my python library which contains my Bot's username and password. I can push code to Git without showing credentials
USERNAME = bot.uG
PASSWORD = bot.pG
USERAGENT = bot.aG
except ImportError:
pass
sql = sqlite3.connect('sql.db')
print('Loaded SQL Database')
cur = sql.cursor()
cur.execute('CREATE TABLE IF NOT EXISTS users(NAME TEXT, POINTS TEXT)')
print('Loaded Completed table')
sql.commit()
print("Logging in")
r = praw.Reddit(USERAGENT)
r.login(USERNAME, PASSWORD)
def operate():
subreddit = r.get_subreddit(SUBREDDIT)
name = input('Get flair for /u/')
flair = subreddit.get_flair(name)
name = flair['user']
flair = flair['flair_text']
if flair:
print(flair)
cur.execute('SELECT * FROM users WHERE NAME=?', [name])
f= cur.fetchone()
if f:
print('updating')
cur.execute('UPDATE users SET POINTS=? WHERE NAME=?', [flair, name])
else:
print('new entry')
cur.execute('INSERT INTO users VALUES(?, ?)', [name, flair])
sql.commit()
else:
print(name, "has no flair")
print()
while True:
operate()
print()