-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanner.py
executable file
·34 lines (26 loc) · 1.03 KB
/
scanner.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
# !/bin/python
# -*- encoding: utf-8 -*-
import json
import praw
import requests
import private
def scan(reddit, limit, subreddit_name):
with open('reddit.json', 'r') as f:
subreddits = json.load(f)
subreddit = reddit.subreddit(subreddit_name)
if subreddit not in subreddits:
subreddits.update({subreddit.display_name: []})
for submission in subreddit.hot(limit=int(limit)):
response = requests.get(submission.url)
if response.status_code == 200:
subreddits[subreddit.display_name].append(submission.url)
print(subreddits)
with open('reddit.json', 'w') as f:
json.dump(subreddits, f)
if __name__ == '__main__':
reddit_agent = praw.Reddit(client_id=private.client_id,
client_secret=private.client_secret,
user_agent=private.user_agent)
target_limit = input('Introduce number of posts ')
target_subreddit = input('Introduce subreddit ')
scan(reddit_agent, target_limit, target_subreddit)