-
Notifications
You must be signed in to change notification settings - Fork 0
/
reddit_scraping.py
50 lines (42 loc) · 1.27 KB
/
reddit_scraping.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 time
import praw
import sqlite3
from credentials import user_agent, reddit
reddit = praw.Reddit(
client_id=reddit['client_id'],
client_secret=reddit['client_secret'],
user_agent=user_agent,
username=reddit['login'],
password=reddit['password']
)
comments = []
users = set()
subreddits = (
# 'Invites', Done
'OpenSignups',
# 'seedboxes',
# 'torrents',
# 'trackers',
)
# В каждом сабреддите отбираем N (limit=) новых записей
# Сохраняем имя автора и id комментария
for item in subreddits:
for item in reddit.subreddit(item).new(limit=None):
if item.author is None:
pass
else:
comments.append(item.id)
users.add(item.author.name)
# Получаем из комментария имя пользователя
for item in comments:
submission = reddit.submission(id=item)
submission.comments.replace_more(limit=None)
for item in submission.comments.list():
if item.author is None:
pass
else:
users.add(item.author.name)
users_db = sqlite3.connect('users.db')
for user in users:
users_db.execute(f"insert or ignore into reddit (user) values('{user}')")
users_db.commit()