-
Notifications
You must be signed in to change notification settings - Fork 1
/
reddit_file.py
34 lines (31 loc) · 1.12 KB
/
reddit_file.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
import praw
import random
import os
def login_reddit():
print("-->Login reddit")
try:
reddit = praw.Reddit(username = os.environ['username'] , password = os.environ['password'] , client_id = os.environ['client_id'] , client_secret = os.environ['client_secret'] , user_agent = "Ninebit")
return reddit
except Exception as e:
print("Exception in reddit authentication function")
print(e)
def obtainaing_sub(reddit,sub):
print("-->Reddit subreddit")
try:
subreddit = reddit.subreddit(sub)
return subreddit
except Exception as e:
print("<>Exception in obtainaing subreddit")
print(e)
def bestpost(subreddit,postidlist):
print("-->Reddit post")
try:
while True:
posts = [post for post in subreddit.hot(limit=30)]
random_post_number = random.randint(0, 30)
submission = posts[random_post_number]
if submission.id not in postidlist:
return submission
except Exception as e:
print("<>Exception in finding best post")
print(e)