-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcbbBot_edit.py
62 lines (54 loc) · 2.51 KB
/
cbbBot_edit.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
60
61
62
#!/Usr/bin/python3
import datetime
import pytz
import time
import cbbBot_text
import cbbBot_data
tz = pytz.timezone('US/Eastern')
try: #import if praw is happy, quit this cycle if not
import praw
print('Imported praw! ' + str(datetime.datetime.now(tz)))
except:
print('Failed to import praw. Shutting down..... ' + str(datetime.datetime.now(tz)))
quit()
with open('./client.txt', 'r') as imp_file:
lines = imp_file.readlines()
lines = [line.replace('\n', '') for line in lines]
try:
r = praw.Reddit(client_id = lines[0], client_secret = lines[1], username = "cbbBot", password = lines[2], user_agent = "CBB Bot v5") #define praw and user agent, login
r.validate_on_submit = True
print('Logged in to Reddit! ' + str(datetime.datetime.now(tz)))
except:
print('Failed to login to Reddit. Shutting down..... ' + str(datetime.datetime.now(tz)))
quit()
while True:
hour, minute = datetime.datetime.now(tz).hour, datetime.datetime.now(tz).minute
if hour == 10 and minute == 6:
quit()
try:
games = cbbBot_data.read_games()
print('Read in games data frame! ' + str(datetime.datetime.now(tz)))
except:
print('Failed to read in games data frame.' + str(datetime.datetime.now(tz)))
time.sleep(5)
continue
if len(games) == 0:
quit()
for game, row in games.iterrows():
if (row['gamethread'] != '') and not any([desc in row['status'].lower() for desc in ['final', 'canceled', 'postponed', 'forfeit']]):
try:
game_data = cbbBot_data.get_game_data(game)
print('Obtained game info for ' + game + '! ' + str(datetime.datetime.now(tz)))
except:
print('Failed to get game info for ' + game + '! ' + str(datetime.datetime.now(tz)))
try:
thread = r.submission(id = row['gamethread'].split('/')[4]) #find already posted thread
comment_stream_link = 'http://www.reddit-stream.com' + thread.permalink
(title, thread_text) = cbbBot_text.make_game_thread(game, game_data, comment_stream_link) #re-write thread
print('Made thread for game ' + game + '! ' + str(datetime.datetime.now(tz)))
thread.edit(body = thread_text) #edit thread
print('Edited thread ' + game + '! ' + str(datetime.datetime.now(tz)))
except:
print('Failed to edit thread ' + game + '. Will continue..... ' + str(datetime.datetime.now(tz)))
time.sleep(10)
time.sleep(5)