-
Notifications
You must be signed in to change notification settings - Fork 3
/
rising.py
30 lines (24 loc) · 1.37 KB
/
rising.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
import praw
import datetime
from config import CLIENT_ID, CLIENT_SECRET, USER_AGENT, REDDIT_USERNAME, REDDIT_PASSWORD, SUBREDDITS, TARGET_SUBREDDIT
def fetch_rising_posts(reddit, subreddit):
rising_posts = []
for submission in reddit.subreddit(subreddit).rising(limit=10):
rising_posts.append((submission.title, submission.url, submission.author.name))
return rising_posts
def compile_rising_digest(reddit):
compiled_content = ""
for subreddit in SUBREDDITS:
rising_posts = fetch_rising_posts(reddit, subreddit)
subreddit_url = f"https://www.reddit.com/r/{subreddit}"
compiled_content += f"**[{subreddit}](https://www.reddit.com/r/{subreddit}) Rising Posts - {datetime.date.today()}**\n\n"
for i, (title, url, author) in enumerate(rising_posts, start=1):
compiled_content += f"{i}. [{title}]({url}) by u/{author}\n\n"
return compiled_content
reddit = praw.Reddit(client_id=CLIENT_ID, client_secret=CLIENT_SECRET, user_agent=USER_AGENT,
username=REDDIT_USERNAME, password=REDDIT_PASSWORD)
rising_digest = compile_rising_digest(reddit)
target_subreddit = TARGET_SUBREDDIT
subreddit = reddit.subreddit(target_subreddit)
submission = subreddit.submit(title=f"Rising Digest - {datetime.date.today()}", selftext=rising_digest)
print(f"Posted to: {submission.url}")