-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert.py
More file actions
62 lines (55 loc) · 1.31 KB
/
insert.py
File metadata and controls
62 lines (55 loc) · 1.31 KB
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
# Import SQLAlchemy stuff
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from db import Post, Base
# Import PRAW
import praw
import time
# Prelim setup
engine = create_engine('sqlite:///praw.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
# Handle ALL Reddit Scraping
##########
# Reddit Setup
r = praw.Reddit('Post Databasing Program')
visited = []
keywords = [
'program design',
'praw',
'study',
'class',
'productivity',
'module',
'framework',
'agency',
'pygame',
'tkinter',
'python',
'C',
'Unity',
'programming standard'
]
# Declare Subs to follow
pythonsub = r.get_subreddit('python')
# Main loop per sub
for submission in pythonsub.get_hot(limit=10):
submission.replace_more_comments(limit=15, threshold=0)
title = submission.title
print('Title Found: %s') % title
post = submission.selftext.lower()
print('Post Found')
link = submission.url
print('Link Found: %s') % link
parsed = praw.helpers.flatten_tree(submission.comments)
commentlist = []
print('Processing Comments...')
for comment in parsed:
commentlist.append(comment.body)
commentlist.append('<===**===>')
comments = ''.join(commentlist)
print('Comments Processed')
new_post = Post(title=title, post=post, comments=comments, link=link)
session.add(new_post)
session.commit()