diff --git a/showcase-sunday/main.py b/showcase-sunday/main.py new file mode 100644 index 0000000..b5192b6 --- /dev/null +++ b/showcase-sunday/main.py @@ -0,0 +1,45 @@ +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' + +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 + + +def create_showcase_sunday_megathread(reddit): + subreddit = reddit.subreddit("developersIndia") + title = "Showcase Sunday Megathread - {month} {year}".format(month=datetime.date.today().strftime("%B"), year=datetime.date.today().year) + text = """ +Welcome to the Showcase Sunday Megathread! +""" + sticky = subreddit.submit(title, selftext=text, send_replies=False) + sticky.mod.sticky(state=True, bottom=True) + # sticky.mod.suggested_sort(sort='new') + sticky.mod.flair(text="Megathread") + return sticky.id + +def main(): + reddit = praw.Reddit( + client_id=client_id, + client_secret=client_secret, + username=username, + password=reddit_pass, + user_agent=user_agent + ) + + if is_second_sunday(): + create_showcase_sunday_megathread(reddit) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/showcase-sunday/test_main.py b/showcase-sunday/test_main.py new file mode 100644 index 0000000..a2c5e89 --- /dev/null +++ b/showcase-sunday/test_main.py @@ -0,0 +1,37 @@ +import unittest +import datetime +from main import is_second_sunday +import unittest.mock + + +# Unit test class +class TestIsSecondSunday(unittest.TestCase): + def test_second_sunday(self): + # Define test cases as a list of tuples containing (input_date, expected_result) + test_cases = [ + (datetime.date(2023, 12, 10), True), + (datetime.date(2024, 1, 14), True), + (datetime.date(2024, 2, 11), True), + ] + + for input_date, expected_result in test_cases: + with unittest.mock.patch("datetime.date") as mock_date: + mock_date.today.return_value = input_date + self.assertEqual(is_second_sunday(), expected_result) + + def test_not_second_sunday(self): + # Define test cases as a list of tuples containing (input_date, expected_result) + test_cases = [ + (datetime.date(2023, 12, 12), False), + (datetime.date(2023, 12, 5), False), + (datetime.date(2023, 12, 19), False), + ] + + for input_date, expected_result in test_cases: + with unittest.mock.patch('datetime.date') as mock_date: + mock_date.today.return_value = input_date + self.assertEqual(is_second_sunday(), expected_result) + + +if __name__ == "__main__": + unittest.main() diff --git a/verified-flair-assign/main.py b/verifier/main.py similarity index 100% rename from verified-flair-assign/main.py rename to verifier/main.py