Skip to content

Commit

Permalink
new script - wiki mention notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhupesh-V committed Nov 5, 2024
1 parent ea7b0e8 commit 7237ed4
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/wiki-mention.yml
Original file line number Diff line number Diff line change
@@ -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 }}
60 changes: 60 additions & 0 deletions wiki-mention/main.py
Original file line number Diff line number Diff line change
@@ -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 <username>")
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()

0 comments on commit 7237ed4

Please sign in to comment.