From d0525e27bafa1d00ecb825b712024f798f8b5a1b Mon Sep 17 00:00:00 2001 From: Bhupesh-V Date: Mon, 1 Jan 2024 20:00:47 +0530 Subject: [PATCH] add automation to execute showcae sunday script everyday --- .github/workflows/showcase-sunday.yml | 35 +++++++++++++++++++ ...es-updater.yml => titles-updater copy.yml} | 0 showcase-sunday/main.py | 9 +++-- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/showcase-sunday.yml rename .github/workflows/{titles-updater.yml => titles-updater copy.yml} (100%) diff --git a/.github/workflows/showcase-sunday.yml b/.github/workflows/showcase-sunday.yml new file mode 100644 index 0000000..392c0b0 --- /dev/null +++ b/.github/workflows/showcase-sunday.yml @@ -0,0 +1,35 @@ +name: r/developersIndia Showcase Sunday Thread + +on: + schedule: + # Run at 3:25 AM UTC (8:55 AM IST) every day + - cron: '25 3 * * *' + workflow_dispatch: + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Create Showcase Sunday Thread + env: + REDDIT_CLIENT_ID: ${{ secrets.REDDIT_CLIENT_ID }} + REDDIT_CLIENT_SECRET: ${{ secrets.REDDIT_CLIENT_SECRET }} + REDDIT_PASSWORD: ${{ secrets.REDDIT_PASSWORD }} + REDDIT_USERNAME: ${{ secrets.REDDIT_USERNAME }} + run: | + cd showcase-sunday + python main.py diff --git a/.github/workflows/titles-updater.yml b/.github/workflows/titles-updater copy.yml similarity index 100% rename from .github/workflows/titles-updater.yml rename to .github/workflows/titles-updater copy.yml diff --git a/showcase-sunday/main.py b/showcase-sunday/main.py index b8ac08e..efa901b 100644 --- a/showcase-sunday/main.py +++ b/showcase-sunday/main.py @@ -21,12 +21,12 @@ def is_second_sunday(): def create_showcase_sunday_megathread(subreddit): flair = next( filter( - lambda flair: flair["flair_text"] == "Showcase Sunday", + lambda flair: "Showcase Sunday" in flair["flair_text"], subreddit.flair.link_templates.user_selectable(), ) ) - title = "Showcase Sunday Megathread - {month} {year}".format(month=datetime.date.today().strftime("%B"), year=datetime.date.today().year) + title = "Showcase Sunday Megathread - {month}, {year}".format(month=datetime.date.today().strftime("%B"), year=datetime.date.today().year) text = """ 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. @@ -38,7 +38,9 @@ Let's inspire each other and celebrate the diverse skills we have. Comment below selftext=text, flair_id=flair["flair_template_id"], ) + submission.mod.approve() submission.mod.sticky() + submission.mod.distinguish() return submission @@ -55,6 +57,9 @@ def main(): if is_second_sunday(): create_showcase_sunday_megathread(subreddit) + print("Showcase Sunday Megathread created successfully!") + else: + print("Skipping. Not the second Sunday of the month") if __name__ == "__main__": main() \ No newline at end of file