-
Notifications
You must be signed in to change notification settings - Fork 0
/
commentbot_progress.py
50 lines (40 loc) · 1.4 KB
/
commentbot_progress.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
import praw
import sqlite3
import time
USERAGENT = "/u/jaytongsays comment bot to help other redditors discover top songs of an artist submitted to a music subreddit"
USERNAME = "bopfm_bot"
PASSWORD = "YOUR PASSWORD"
SUBREDDIT = 'listentothis'
LIMIT = 10
KEYWORDS = [" -- "," - "]
WAIT = 600
print("logging in")
r = praw.Reddit(USERAGENT)
r.login(USERNAME, PASSWORD)
sql = sqlite3.connect('sql.db')
print('Loaded SQL Database')
cur = sql.cursor()
cur.execute('CREATE TABLE IF NOT EXISTS oldposts(ID TEXT)')
print("Loaded Database")
def scan():
print("starting scan")
subreddit = r.get_subreddit(SUBREDDIT)
for submission in subreddit.get_new(limit=LIMIT):
cur.execute('SELECT * FROM oldposts WHERE ID=?', [submission.url])
if not cur.fetchone():
cur.execute('INSERT INTO oldposts VALUES(?)', [submission.url])
title = submission.title.encode()
for key in KEYWORDS:
if key in title:
print(title)
before, after = title.split(key)
print(before)
submission.add_comment("If this is the first time anyone has heard of " + before + ", check out " + before + "'s other top songs: https://bop.fm/a/"+str.lower(before.replace(' ','-').replace('&','and')) + " If the link isn't working for some reason, reply back and I'll fix it!")
sql.commit()
while True:
try:
scan()
except:
print('Failed to scan')
print('Waiting ' + str(WAIT) + ' seconds')
time.sleep(WAIT)