Skip to content

Commit

Permalink
add ama posts in roundup
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhupesh-V committed Jan 20, 2024
1 parent 1c85fa5 commit ee24bdc
Showing 1 changed file with 43 additions and 19 deletions.
62 changes: 43 additions & 19 deletions community-roundup/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import praw
import os
import sys
import json
import requests

Expand Down Expand Up @@ -43,6 +44,15 @@ def get_weekly_discussion_posts(subreddit):

return get_posts_by_flair(subreddit, flair["flair_text"])

def get_ama_posts(subreddit):
flair = next(
filter(
lambda flair: "AMA" in flair["flair_text"],
subreddit.flair.link_templates.user_selectable(),
)
)

return get_posts_by_flair(subreddit, flair["flair_text"])

def get_i_made_this_posts(subreddit):
flair = next(
Expand Down Expand Up @@ -73,7 +83,7 @@ def get_gist_content(gist_id):
return gist["files"][filename]["content"]


def get_monthly_roundup():
def get_community_threads():
saved_collection_posts = json.loads(get_gist_content(gist_id))
# filter posts for this month & year
saved_collection_posts = list(
Expand All @@ -90,7 +100,7 @@ def get_monthly_roundup():
return saved_collection_posts


def create_community_roundup_post(subreddit, posts, i_made_this_posts, weekly_discussion_posts):
def create_community_roundup_post(subreddit, posts, i_made_this_posts, weekly_discussion_posts, ama_posts):
flair = next(
filter(
lambda flair: "Community Roundup" in flair["flair_text"],
Expand All @@ -102,27 +112,43 @@ def create_community_roundup_post(subreddit, posts, i_made_this_posts, weekly_di
month=datetime.date.today().strftime("%B"), year=datetime.date.today().year
)

text = "\n## Community Threads\n|S.No|Discussions started by members|"
text += "\n|--------|--------|\n"
footer_text = """\n\n
---
**Community Roundup is posted on the last day of each month. To explore a compilation of all interesting posts and community threads over time, [visit our wiki](https://www.reddit.com/r/developersIndia/wiki/community-threads/).**\n
The collection is curated by our volunteer team & is independent of the number of upvotes and comments (except for "I made This" posts). If you believe we may have overlooked any engaging posts or discussions, please share them with us via [modmail](https://reddit.com/message/compose?to=r/developersIndia&subject=Community%20Threads%20Collection%20Suggestion&message=Hey%20folks%2C%0A%0A%3Cpost%20link%3E).\n
"""
posts_counter = 0
for post in posts:
posts_counter += 1
text += f"| {posts_counter} | [**{post['title']}**]({post['url']}) |\n"

text += "\n## Weekly Discussions\n|Started by Volunteer/Mod Team|\n|--------|\n"
for post in weekly_discussion_posts:
text += f"| [**{post.title}**]({post.url}) |\n"
if len(ama_posts) > 0:
text = "\n## AMAs\n||\n|--------|\n"
for post in ama_posts:
text += f"| [**{post.title}**]({post.url}) |\n"
else:
print("No AMAs found. Skipping")

if len(posts) > 0:
text += "\n## Community Threads\n|S.No|Discussions started by members|\n|--------|--------|\n"
posts_counter = 0
for post in posts:
posts_counter += 1
text += f"| {posts_counter} | [**{post['title']}**]({post['url']}) |\n"
else:
print("No posts found in the collection for this month. Skipping")

if len(weekly_discussion_posts) > 0:
text += "\n## Weekly Discussions\n|Started by Volunteer/Mod Team|\n|--------|\n"
for post in weekly_discussion_posts:
text += f"| [**{post.title}**]({post.url}) |\n"
else:
print("No weekly discussions found. Skipping")


text += "## I Made This\n|Top 10 posts|\n|--------|\n"
for post in i_made_this_posts:
text += f"| [**{post.title}**]({post.url}) |\n"
if len(i_made_this_posts) > 0:
text += "\n## I Made This\n|Top 10 posts|\n|--------|\n"
for post in i_made_this_posts:
text += f"| [**{post.title}**]({post.url}) |\n"
else:
print("No I Made This posts found. Skipping")


text = text + footer_text
Expand Down Expand Up @@ -152,13 +178,11 @@ def main():
subreddit = reddit.subreddit(sub)

if is_last_day_of_month():
posts = get_monthly_roundup()
if len(posts) == 0:
print("No posts found in the collection for this month. Skipping")
return
posts = get_community_threads()
i_made_this_posts = get_i_made_this_posts(subreddit)
weekly_discussion_posts = get_weekly_discussion_posts(subreddit)
create_community_roundup_post(subreddit, posts, i_made_this_posts, weekly_discussion_posts)
ama_posts = get_ama_posts(subreddit)
create_community_roundup_post(subreddit, posts, i_made_this_posts, weekly_discussion_posts, ama_posts)
print("Community Roundup post created successfully!")
else:
print("Skipping. Not the last day of the month")
Expand Down

0 comments on commit ee24bdc

Please sign in to comment.