forked from zackmawaldi/YouTube-shorts-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreddit_scraper.py
40 lines (29 loc) · 1.23 KB
/
reddit_scraper.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
import praw
from redvid import Downloader
import os
import config
def download_vid(url, directory): # Download reddit vid given URL and directory
download = Downloader(url, max_q=True)
download.path = directory
download.download()
print(os.listdir(directory))
def reddit_scraper(subreddit): # pulls out top reddit posts
print("Logging into Reddit...")
red = praw.Reddit(client_id=config.reddit_login['client_id'],
client_secret=config.reddit_login['client_secret'],
password=config.reddit_login['password'],
user_agent=config.reddit_login['user_agent'],
username=config.reddit_login['username'])
print("Log in success! Retrieving post info...")
sub = red.subreddit(subreddit).top("week", limit=25)
output = []
for i in sub:
print(f"{i.title}")
if not i.stickied and not i.over_18:
url = i.url
if url.split('.')[0] != 'https://v':
continue
title = i.title
print('{} {} {}\n{}\n'.format(title, i.subreddit, i.author.name, url))
output.append((url, title, i.author.name))
return output