2023-12-27 20:35:31 +05:30
import datetime
import praw
import os
client_id = os . environ [ " REDDIT_CLIENT_ID " ]
client_secret = os . environ [ " REDDIT_CLIENT_SECRET " ]
reddit_pass = os . environ [ " REDDIT_PASSWORD " ]
username = os . environ [ " REDDIT_USERNAME " ]
user_agent = ' Showcase Sunday Megathread '
2023-12-28 22:47:40 +05:30
sub = " developersIndia "
2023-12-27 20:35:31 +05:30
def is_second_sunday ( ) :
today = datetime . date . today ( )
first_day_of_month = today . replace ( day = 1 )
day_of_week = first_day_of_month . weekday ( )
# Calculate the date of the second Sunday
second_sunday = first_day_of_month + datetime . timedelta ( days = ( 6 - day_of_week + 7 ) % 7 + 7 )
return today == second_sunday
2023-12-28 22:47:40 +05:30
def create_showcase_sunday_megathread ( subreddit ) :
flair = next (
filter (
2024-01-01 20:00:47 +05:30
lambda flair : " Showcase Sunday " in flair [ " flair_text " ] ,
2023-12-28 22:47:40 +05:30
subreddit . flair . link_templates . user_selectable ( ) ,
)
)
2024-01-01 20:00:47 +05:30
title = " Showcase Sunday Megathread - {month} , {year} " . format ( month = datetime . date . today ( ) . strftime ( " % B " ) , year = datetime . date . today ( ) . year )
2023-12-27 20:35:31 +05:30
text = """
2023-12-28 22:47:40 +05:30
It ' s time for our monthly showcase thread where we celebrate the incredible talent in our community. Whether it ' s an app , a website , a tool , or anything else you ' ve built, we want to see it! Share your latest creations, side projects, or even your work-in-progress.
Let ' s inspire each other and celebrate the diverse skills we have. Comment below with details about what you ' ve built , the tech stack used , and any interesting challenges faced along the way .
2024-01-13 16:50:59 +05:30
* * Showcase Sunday thread is posted on the second Sunday of every month . You can find the [ schedule on our calendar ] ( https : / / developersindia . in / events - calendar ) . * *
2023-12-27 20:35:31 +05:30
"""
2023-12-28 22:47:40 +05:30
submission = subreddit . submit (
title ,
selftext = text ,
flair_id = flair [ " flair_template_id " ] ,
)
2024-01-01 20:00:47 +05:30
submission . mod . approve ( )
2023-12-28 22:47:40 +05:30
submission . mod . sticky ( )
2024-01-01 20:00:47 +05:30
submission . mod . distinguish ( )
2023-12-28 22:47:40 +05:30
return submission
2023-12-27 20:35:31 +05:30
def main ( ) :
reddit = praw . Reddit (
client_id = client_id ,
client_secret = client_secret ,
username = username ,
password = reddit_pass ,
user_agent = user_agent
)
2023-12-28 22:47:40 +05:30
subreddit = reddit . subreddit ( sub )
2023-12-27 20:35:31 +05:30
if is_second_sunday ( ) :
2023-12-28 22:47:40 +05:30
create_showcase_sunday_megathread ( subreddit )
2024-01-01 20:00:47 +05:30
print ( " Showcase Sunday Megathread created successfully! " )
else :
print ( " Skipping. Not the second Sunday of the month " )
2023-12-27 20:35:31 +05:30
if __name__ == " __main__ " :
main ( )