From 7237ed4e0286baad97ebde394af43ba54f99e47a Mon Sep 17 00:00:00 2001 From: Bhupesh-V Date: Wed, 6 Nov 2024 00:07:19 +0530 Subject: [PATCH] new script - wiki mention notifier --- .github/workflows/wiki-mention.yml | 35 +++++++++++++++++ wiki-mention/main.py | 60 ++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 .github/workflows/wiki-mention.yml create mode 100644 wiki-mention/main.py diff --git a/.github/workflows/wiki-mention.yml b/.github/workflows/wiki-mention.yml new file mode 100644 index 0000000..6131f15 --- /dev/null +++ b/.github/workflows/wiki-mention.yml @@ -0,0 +1,35 @@ +name : Wiki Mention Notifier + +on: + workflow_dispatch: + inputs: + username: + description: 'The username of the community member to notify' + required: true + +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: Update Wiki + 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 wiki-mention + python main.py ${{ github.event.inputs.username }} \ No newline at end of file diff --git a/wiki-mention/main.py b/wiki-mention/main.py new file mode 100644 index 0000000..1129e40 --- /dev/null +++ b/wiki-mention/main.py @@ -0,0 +1,60 @@ +import praw +import os + +# Reddit API credentials +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 = "Wiki Mention Notifier" +sub = "developersIndia" + +# Create a Reddit instance +reddit = praw.Reddit( + client_id=client_id, + client_secret=client_secret, + password=reddit_pass, + user_agent=user_agent, + username=username, +) + +def send_message(reddit, username): + message_subject = 'Woohoo! Your advice/perspective is now part of our wiki!' + message_text = """ +Hi there,\n +It looks like one of your comments on r/developersIndia was picked-up by the volunteer team to be part of our [community-driven wiki](https://wiki.developersindia.in/).\n + +- You can find your advice by searching your username in our [Wiki](https://wiki.developersindia.in/).\n +- We can't thank you enough for your valuable contribution to our community 🧡\n\n + +Please keep contributing productively!\n + +Cheers,\n +The r/developersIndia Community Team +""" + reddit.redditor(username).message( + subject=message_subject, message=message_text, from_subreddit=reddit.subreddit(sub) + ) + + +def add_mod_note_good_contributor(reddit, username): + subreddit = reddit.subreddit(sub) + subreddit.mod.notes.create( + redditor=username, + label="HELPFUL_USER", + note="Their advice/perspective was mentioned in our wiki.", + ) + +def main(): + if len(os.sys.argv) != 2: + print("Usage: python main.py ") + return + + reddit_username = os.sys.argv[1] + + send_message(reddit, reddit_username) + add_mod_note_good_contributor(reddit, reddit_username) + print(f"Sent wiki mention modmail to {reddit_username}") + +if __name__ == "__main__": + main() \ No newline at end of file