-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
55 lines (47 loc) · 1.83 KB
/
bot.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
import praw
import config
import datetime
from mongoengine import *
from resume import Resume
class Bot():
def __init__(self):
self.count=0
def bot_login(self):
r = praw.Reddit(username = config.username,
password = config.password,
client_id = config.client_id,
client_secret = config.client_secret,
user_agent = config.user_agent)
return r
def run_bot(self, r):
subreddit = r.subreddit('cscareerquestions')
for submission in subreddit.search("author:AutoModerator Resume"):
print("Processing: " + submission.title)
self.process_submission(submission)
def process_submission(self, submission):
connect('resume_test', host='localhost', port=27017)
submission.comments.replace_more(limit=0)
for top_level_comment in submission.comments:
s = top_level_comment.body
if "(http" in s:
date = datetime.datetime.fromtimestamp(submission.created_utc).isoformat()
author = top_level_comment.author
img_url = s[s.find("(http")+1:s.find(")")]
if author != None and img_url.startswith('http'):
#img_url = s[s.find("(http")+1:s.find(")")]
print("Writing: " + author.name + " " + img_url + " to database..."),
post = Resume(
author=author.name,
url=img_url,
post_date=date
)
post.save()
self.count += 1
print("Done!")
print(post.author)
break
resume_bot = Bot()
print(resume_bot.count)
r = resume_bot.bot_login()
resume_bot.run_bot(r)
print(str(resume_bot.count) + " records written.")