mirror of
https://github.com/developersIndia/deviras.git
synced 2025-05-31 14:11:43 +05:30
Compare commits
36 Commits
dc7a04b9b1
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
3feccf6755 | ||
|
101b529307 | ||
|
e9a454fa5a | ||
|
345dc1016e | ||
|
2824227ac9 | ||
|
e84b1b18ae | ||
|
a73d956b23 | ||
|
bcb037076a | ||
|
8ceaefcce9 | ||
|
7237ed4e02 | ||
|
ea7b0e8a37 | ||
|
aeed19753e | ||
|
87cd738f3e | ||
|
676744cb6f | ||
|
3b6d74c683 | ||
|
282d02d000 | ||
|
7c90a350e9 | ||
|
24be5dcd82 | ||
|
bcd0648167 | ||
|
50a57664ba | ||
|
44d765927c | ||
|
069293ea5e | ||
|
4e26a3f764 | ||
|
17967c3b95 | ||
|
10ce6e5528 | ||
|
f2b11ddd21 | ||
|
e5b36db49f | ||
|
fe0c6a6a57 | ||
|
8c5ecda424 | ||
|
21fce6828b | ||
|
58746803ee | ||
|
518f650160 | ||
|
1dad8740e6 | ||
|
2df84308dd | ||
|
512a469fde | ||
|
ed2e865492 |
@@ -50,6 +50,24 @@
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "LinearArray",
|
||||
"name": "LinearArray",
|
||||
"avatar_url": "https://github.com/lineararray.png",
|
||||
"profile": "https://github.com/lineararray",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "Rancho-rachit",
|
||||
"name": "Rachit Agrawal",
|
||||
"avatar_url": "https://avatars.githubusercontent.com/u/111473259?v=4",
|
||||
"profile": "https://rancho-rachit.github.io/",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
}
|
||||
],
|
||||
"contributorsPerLine": 7,
|
||||
|
59
.github/workflows/aoc.yml
vendored
59
.github/workflows/aoc.yml
vendored
@@ -1,37 +1,38 @@
|
||||
name : AoC leaderboard
|
||||
name: AoC leaderboard
|
||||
|
||||
on:
|
||||
# schedule:
|
||||
# Every 2 hours”
|
||||
# - cron: '0 */2 * * *'
|
||||
workflow_dispatch:
|
||||
# schedule:
|
||||
# Run every 24 hours at 00:00 UTC
|
||||
# - cron: "0 0 * * *"
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
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 Learderboard
|
||||
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 }}
|
||||
AOC_SESSION_COOKIE: ${{ secrets.AOC_SESSION_COOKIE }}
|
||||
AOC_LEADERBOARD_CODE: ${{ secrets.AOC_LEADERBOARD_CODE }}
|
||||
REDDIT_POST_ID: ${{ secrets.REDDIT_POST_ID }}
|
||||
run: |
|
||||
cd aoc
|
||||
python main.py
|
||||
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 Leaderboard
|
||||
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 }}
|
||||
AOC_SESSION_COOKIE: ${{ secrets.AOC_SESSION_COOKIE }}
|
||||
AOC_LEADERBOARD_CODE: ${{ secrets.AOC_LEADERBOARD_CODE }}
|
||||
AOC_LEADERBOARD_REDDIT_POST_ID: ${{ secrets.AOC_LEADERBOARD_REDDIT_POST_ID }}
|
||||
AOC_YEAR: ${{ secrets.AOC_YEAR }}
|
||||
run: |
|
||||
cd aoc
|
||||
python main.py
|
||||
|
35
.github/workflows/wiki-mention.yml
vendored
Normal file
35
.github/workflows/wiki-mention.yml
vendored
Normal file
@@ -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 }}
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -127,3 +127,5 @@ dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
*.csv
|
@@ -21,7 +21,7 @@
|
||||
|
||||
### [community-threads](https://github.com/developersIndia/deviras/blob/main/community-threads/main.py)
|
||||
|
||||
- Used for grabbing the posts from [community threads collection](https://www.reddit.com/r/developersIndia/collection/958aef35-f9cb-414d-ab33-08bc639e47de/) and adding it to the [wiki](https://www.reddit.com/r/developersIndia/wiki/community-threads/).
|
||||
- Add a post to [community threads wiki](https://www.reddit.com/r/developersIndia/wiki/community-threads/).
|
||||
- 
|
||||
|
||||
### [job-thread](https://github.com/developersIndia/deviras/blob/main/job-thread/main.py)
|
||||
@@ -79,10 +79,10 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://animesh-ghosh.github.io/"><img src="https://avatars.githubusercontent.com/u/34956994?v=4?s=100" width="100px;" alt="MaDDogx"/><br /><sub><b>MaDDogx</b></sub></a><br /><a href="https://github.com/developersIndia/deviras/commits?author=Animesh-Ghosh" title="Code">💻</a> <a href="https://github.com/developersIndia/deviras/commits?author=Animesh-Ghosh" title="Tests">⚠️</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://pratham.cc"><img src="https://avatars.githubusercontent.com/u/67585967?v=4?s=100" width="100px;" alt="Pratham"/><br /><sub><b>Pratham</b></sub></a><br /><a href="https://github.com/developersIndia/deviras/commits?author=git-bruh" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://nisarga.me/"><img src="https://avatars.githubusercontent.com/u/45588772?v=4?s=100" width="100px;" alt="Nisarga Adhikary"/><br /><sub><b>Nisarga Adhikary</b></sub></a><br /><a href="https://github.com/developersIndia/deviras/commits?author=ni5arga" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://lineararray.nekoweb.org"><img src="https://github.com/lineararray.png" width="100px;" alt="LinearArray"/><br /><sub><b>LinearArray</b></sub></a><br /><a href="https://github.com/developersIndia/deviras/commits?author=LinearArray" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/lineararray"><img src="https://github.com/lineararray.png?s=100" width="100px;" alt="LinearArray"/><br /><sub><b>LinearArray</b></sub></a><br /><a href="https://github.com/developersIndia/deviras/commits?author=LinearArray" title="Code">💻</a></td>
|
||||
<td align="center" valign="top" width="14.28%"><a href="https://rancho-rachit.github.io/"><img src="https://avatars.githubusercontent.com/u/111473259?v=4?s=100" width="100px;" alt="Rachit Agrawal"/><br /><sub><b>Rachit Agrawal</b></sub></a><br /><a href="https://github.com/developersIndia/deviras/commits?author=Rancho-rachit" title="Code">💻</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
<!-- markdownlint-restore -->
|
||||
|
20
aoc/main.py
20
aoc/main.py
@@ -6,20 +6,21 @@ 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 = 'AdventOfCode Leaderboard Updater (by https://github.com/ni5arga/)'
|
||||
user_agent = 'AdventOfCode Leaderboard Updater - developersIndia'
|
||||
aoc_session_cookie = os.environ["AOC_SESSION_COOKIE"]
|
||||
aoc_leaderboard_code = os.environ["AOC_LEADERBOARD_CODE"]
|
||||
reddit_post_id = os.environ.get("REDDIT_POST_ID")
|
||||
aoc_year = os.environ.get("AOC_YEAR")
|
||||
reddit_post_id = os.environ.get("AOC_LEADERBOARD_REDDIT_POST_ID")
|
||||
|
||||
aoc_url = f'https://adventofcode.com/{{year}}/leaderboard/private/view/{aoc_leaderboard_code}.json'
|
||||
aoc_url = f'https://adventofcode.com/{aoc_year}/leaderboard/private/view/{aoc_leaderboard_code}.json'
|
||||
|
||||
def get_leaderboard_data():
|
||||
response = requests.get(aoc_url.format(year=2023), cookies={'session': aoc_session_cookie})
|
||||
response = requests.get(aoc_url.format(year=aoc_year), cookies={'session': aoc_session_cookie})
|
||||
data = response.json()
|
||||
return data
|
||||
|
||||
def format_leaderboard(data, num_players=100):
|
||||
leaderboard_stats = "r/developersIndia Advent of Code Leaderboard Stats\n\n"
|
||||
leaderboard_stats = f"r/developersIndia Advent of Code {aoc_year} - Leaderboard\n\n"
|
||||
leaderboard_stats += "| Rank | Player | Stars | Score |\n"
|
||||
leaderboard_stats += "|------|--------|-------|-------|\n"
|
||||
|
||||
@@ -30,9 +31,12 @@ def format_leaderboard(data, num_players=100):
|
||||
for i, member_data in enumerate(sorted_members[:num_players]):
|
||||
# check for non-zero local_score
|
||||
if member_data['local_score'] > 0:
|
||||
# if member's name is null, use the member_id
|
||||
if member_data['name'] == None:
|
||||
member_data['name'] = f"Anonymous #{member_data['id']}"
|
||||
|
||||
leaderboard_stats += f"| {i + 1} | {member_data['name']} | {member_data['stars']} | {member_data['local_score']} |\n"
|
||||
|
||||
leaderboard_stats += f"\n[Advent of Code Leaderboard](https://adventofcode.com/2023/leaderboard/private/view/{aoc_leaderboard_code})\n"
|
||||
leaderboard_stats += f"\nUpdated every 24 hours"
|
||||
|
||||
return leaderboard_stats
|
||||
@@ -43,7 +47,7 @@ def update_reddit_post(reddit, post_id, new_stats):
|
||||
|
||||
def main():
|
||||
if not reddit_post_id:
|
||||
print("Please set the REDDIT_POST_ID environment variable.")
|
||||
print("Please set the AOC_LEADERBOARD_REDDIT_POST_ID environment variable.")
|
||||
return
|
||||
|
||||
reddit = praw.Reddit(
|
||||
@@ -55,9 +59,7 @@ def main():
|
||||
)
|
||||
|
||||
leaderboard_data = get_leaderboard_data()
|
||||
|
||||
formatted_stats = format_leaderboard(leaderboard_data)
|
||||
|
||||
update_reddit_post(reddit, reddit_post_id, formatted_stats)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@@ -1,27 +1,28 @@
|
||||
# AoC Private Leaderboard Stats Updater Script for Reddit
|
||||
|
||||
## Required Environment Variables
|
||||
## Required Environment Variables
|
||||
|
||||
|
||||
1. `REDDIT_CLIENT_ID`: Reddit API client ID.
|
||||
2. `REDDIT_CLIENT_SECRET`: Reddit API client secret.
|
||||
3. `REDDIT_PASSWORD`: Reddit account password.
|
||||
4. `REDDIT_USERNAME`: Reddit account username.
|
||||
5. `AOC_SESSION_COOKIE`: Session cookie for the Advent of Code website.
|
||||
6. `AOC_LEADERBOARD_CODE`: Code for the Advent of Code leaderboard.
|
||||
7. `REDDIT_POST_ID`: ID of Reddit post which is used as leaderboard.
|
||||
1. `REDDIT_CLIENT_ID`: Reddit API client ID.
|
||||
2. `REDDIT_CLIENT_SECRET`: Reddit API client secret.
|
||||
3. `REDDIT_PASSWORD`: Reddit account password.
|
||||
4. `REDDIT_USERNAME`: Reddit account username.
|
||||
5. `AOC_SESSION_COOKIE`: Session cookie for the Advent of Code website.
|
||||
6. `AOC_LEADERBOARD_CODE`: Code for the Advent of Code leaderboard.
|
||||
7. `AOC_LEADERBOARD_REDDIT_POST_ID`: ID of Reddit post which is used as leaderboard.
|
||||
|
||||
----
|
||||
|
||||
## Instructions on how to get `AOC_SESSION_COOKIE`
|
||||
|
||||
1. **Create an Advent of Code Account:**
|
||||
- If you don't have an Advent of Code account, go to the [Advent of Code website](https://adventofcode.com/), and sign up for an account.
|
||||
|
||||
2. **Log into Your AoC Account & open the leaderboard**
|
||||
- After creating an account, log into the AoC website using your credentials. Make sure you have joined the private leaderboard which's ID you have set in `AOC_LEADERBOARD_CODE`. Now navigate to the leaderboard page.
|
||||
|
||||
|
||||
3. **Open Developer Tools in Your Browser:**
|
||||
- Open the browser's developer tools. You can usually do this by right-clicking on the web page, selecting "Inspect" or "Inspect Element," and then navigating to the "Network" tab.
|
||||
|
||||
|
||||
4. **Go to the Network Tab:**
|
||||
- In the developer tools, go to the "Network" tab. This tab will show all network requests made by the website.
|
||||
|
||||
@@ -41,8 +42,4 @@
|
||||
9. **Use the Session Cookie:**
|
||||
- Paste the copied session cookie value into the appropriate environment variable (`AOC_SESSION_COOKIE` in this case) in your code or set it as an environment variable.
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
|
||||

|
||||
|
@@ -27,7 +27,7 @@ def get_posts_by_flair(subreddit, flair):
|
||||
posts = []
|
||||
for post in subreddit.search(f'flair_name:"{flair}"', time_filter="month"):
|
||||
post_date = datetime.datetime.fromtimestamp(post.created_utc)
|
||||
if post_date.year == current_year and post_date.month == current_month:
|
||||
if post_date.year == current_year and post_date.month == current_month and post.selftext != '[deleted]':
|
||||
post.title = post.title.replace("|", "\\|") # Escape the "|" character
|
||||
posts.append(post)
|
||||
|
||||
@@ -74,7 +74,7 @@ def get_i_made_this_posts(subreddit):
|
||||
)
|
||||
|
||||
# Return only the top 10 posts
|
||||
return posts[:10]
|
||||
return posts[:20]
|
||||
|
||||
|
||||
def get_announcement_posts(subreddit):
|
||||
@@ -88,6 +88,16 @@ def get_announcement_posts(subreddit):
|
||||
return get_posts_by_flair(subreddit, flair["flair_text"])
|
||||
|
||||
|
||||
def code_collaboration_posts(subreddit):
|
||||
flair = next(
|
||||
filter(
|
||||
lambda flair: "Code Collab" in flair["flair_text"],
|
||||
subreddit.flair.link_templates.user_selectable(),
|
||||
)
|
||||
)
|
||||
|
||||
return get_posts_by_flair(subreddit, flair["flair_text"])
|
||||
|
||||
def get_gist_content(gist_id):
|
||||
headers = {
|
||||
"Authorization": f"token {token}",
|
||||
@@ -125,6 +135,7 @@ def create_community_roundup_post(
|
||||
weekly_discussion_posts,
|
||||
ama_posts,
|
||||
announcement_posts,
|
||||
collab_posts,
|
||||
):
|
||||
flair = next(
|
||||
filter(
|
||||
@@ -133,7 +144,7 @@ def create_community_roundup_post(
|
||||
)
|
||||
)
|
||||
|
||||
title = "Community Roundup: List of must read posts & discussions that happened this month - {month} {year}".format(
|
||||
title = "Community Roundup: List of interesting discussions that happened in {month} {year}".format(
|
||||
month=datetime.date.today().strftime("%B"), year=datetime.date.today().year
|
||||
)
|
||||
|
||||
@@ -143,23 +154,24 @@ def create_community_roundup_post(
|
||||
**Community Roundup is posted on the last day of each month. To explore a compilation of all interesting posts and community threads over time, [visit our wiki](https://www.reddit.com/r/developersIndia/wiki/community-threads/).**\n
|
||||
The collection is curated by our volunteer team & is independent of the number of upvotes and comments (except for "I made This" posts). If you believe we may have overlooked any engaging posts or discussions, please share them with us via [modmail](https://reddit.com/message/compose?to=r/developersIndia&subject=Community%20Threads%20Collection%20Suggestion&message=Hey%20folks%2C%0A%0A%3Cpost%20link%3E).\n
|
||||
"""
|
||||
text = ""
|
||||
|
||||
if len(announcement_posts) > 0:
|
||||
text = "## Announcements\n||\n|--------|\n"
|
||||
text = "## Announcements\n|Announcements from volunteer team|\n|--------|\n"
|
||||
for post in announcement_posts:
|
||||
text += f"| [**{post.title}**]({post.url}) |\n"
|
||||
text += f"| [**{post.title.strip()}**]({post.url}) |\n"
|
||||
else:
|
||||
print("No announcements found. Skipping")
|
||||
|
||||
if len(ama_posts) > 0:
|
||||
text += "\n## AMAs\n||\n|--------|\n"
|
||||
text += "\n## AMAs\n|Read insights from guests that joined us for a day |\n|--------|\n"
|
||||
for post in ama_posts:
|
||||
text += f"| [**{post.title}**]({post.url}) |\n"
|
||||
text += f"| [**{post.title.strip()}**]({post.url}) |\n"
|
||||
else:
|
||||
print("No AMAs found. Skipping")
|
||||
|
||||
if len(posts) > 0:
|
||||
text += "\n## Community Threads\n|S.No|Discussions started by members|\n|--------|--------|\n"
|
||||
text += "\n## Community Threads\n|S.No|Insightful discussions started by community members|\n|--------|--------|\n"
|
||||
posts_counter = 0
|
||||
for post in posts:
|
||||
posts_counter += 1
|
||||
@@ -168,16 +180,24 @@ The collection is curated by our volunteer team & is independent of the number o
|
||||
print("No posts found in the collection for this month. Skipping")
|
||||
|
||||
if len(weekly_discussion_posts) > 0:
|
||||
text += "\n## Weekly Discussions\n|Started by Volunteer/Mod Team|\n|--------|\n"
|
||||
text += "\n## Weekly Discussions\n|Weekly tech discussions started by Volunteer Team|\n|--------|\n"
|
||||
for post in weekly_discussion_posts:
|
||||
text += f"| [**{post.title}**]({post.url}) |\n"
|
||||
text += f"| [**{post.title.strip()}**]({post.url}) |\n"
|
||||
else:
|
||||
print("No weekly discussions found. Skipping")
|
||||
|
||||
if len(collab_posts) > 0:
|
||||
text += "\n## Code Collab\n|Folks looking for collaborations on hackathons, projects etc.|\n|--------|\n"
|
||||
for post in collab_posts:
|
||||
text += f"| [**{post.title.strip()}**]({post.url}) |\n"
|
||||
else:
|
||||
print("No Code Collaboration posts found. Skipping")
|
||||
|
||||
if len(i_made_this_posts) > 0:
|
||||
text += "\n## I Made This\n|Top 10 posts|\n|--------|\n"
|
||||
text += "\n## I Made This\n\nFind more projects & builders on our [Showcase Sunday Megathreads](https://www.reddit.com/r/developersIndia/?f=flair_name%3A%22Showcase%20Sunday%20%3Asnoo_hearteyes%3A%22)\n\n"
|
||||
text += "|Top 20 projects built by community members|\n|--------|\n"
|
||||
for post in i_made_this_posts:
|
||||
text += f"| [**{post.title}**]({post.url}) |\n"
|
||||
text += f"| [**{post.title.strip()}**]({post.url}) |\n"
|
||||
else:
|
||||
print("No I Made This posts found. Skipping")
|
||||
|
||||
@@ -213,8 +233,9 @@ def main():
|
||||
weekly_discussion_posts = get_weekly_discussion_posts(subreddit)
|
||||
ama_posts = get_ama_posts(subreddit)
|
||||
announcement_posts = get_announcement_posts(subreddit)
|
||||
collab_posts = code_collaboration_posts(subreddit)
|
||||
create_community_roundup_post(
|
||||
subreddit, posts, i_made_this_posts, weekly_discussion_posts, ama_posts, announcement_posts
|
||||
subreddit, posts, i_made_this_posts, weekly_discussion_posts, ama_posts, announcement_posts, collab_posts
|
||||
)
|
||||
print("Community Roundup post created successfully!")
|
||||
else:
|
||||
|
@@ -44,17 +44,36 @@ def update_gist(gist_id, filename, content, description=""):
|
||||
# )
|
||||
# return collection
|
||||
|
||||
# let the author know their post is now part of the collection!
|
||||
def send_message(reddit, username, post_link):
|
||||
message_subject = 'Woohoo! Your post is now part of our community threads collection!'
|
||||
message_text = """
|
||||
Hi there,\n
|
||||
It looks like one of your [posts]({post_link}) on r/developersIndia was picked-up by the volunteer team to be part of our curated list of 200+ amazing discussions in the community.\n
|
||||
|
||||
- You can find your post in our [Community Threads Collection](https://reddit.com/r/developersIndia/wiki/community-threads). Feel free to share the collection with your dev friends.\n
|
||||
- We post a compilation of these threads every month-end in [Community Roundups](https://www.reddit.com/r/developersIndia/?f=flair_name%3A%22Community%20Roundup%22). Stay tuned for the next one!\n
|
||||
|
||||
|
||||
Cheers,\n
|
||||
The r/developersIndia Community Team
|
||||
"""
|
||||
reddit.redditor(username).message(
|
||||
subject=message_subject, message=message_text.format(post_link=post_link), from_subreddit=reddit.subreddit(sub)
|
||||
)
|
||||
|
||||
def get_post_data(reddit, post_url):
|
||||
submission = reddit.submission(url=post_url)
|
||||
post = {
|
||||
"title": submission.title,
|
||||
"url": submission.url,
|
||||
"url": submission.permalink,
|
||||
"id": submission.id,
|
||||
"num_comments": submission.num_comments,
|
||||
"created_at": datetime.utcfromtimestamp(
|
||||
submission.created_utc
|
||||
).isoformat(),
|
||||
"flair_text": submission.link_flair_text,
|
||||
"author": submission.author.name if submission.author else "",
|
||||
}
|
||||
return post
|
||||
|
||||
@@ -123,6 +142,7 @@ def main():
|
||||
|
||||
new_post = get_post_data(reddit, args.post_url)
|
||||
if new_post["id"] not in saved_collection_ids:
|
||||
new_post["title"] = new_post["title"].strip()
|
||||
posts.append(new_post)
|
||||
posts = sorted(posts, key=lambda k: k["created_at"])
|
||||
|
||||
@@ -134,6 +154,12 @@ def main():
|
||||
update_gist(gist_id, "collection.json", json.dumps(collection_json, indent=4))
|
||||
print("Internal database updated successfully!")
|
||||
update_wiki(reddit, "community-threads", posts)
|
||||
if new_post["author"]:
|
||||
send_message(reddit, new_post["author"], new_post["url"])
|
||||
print("Message sent to the author!")
|
||||
else:
|
||||
print("Author username is empty. No message sent.")
|
||||
|
||||
else:
|
||||
print("Post is already in the collection. No changes were made.")
|
||||
|
||||
|
17
event-manager/.env.sample
Normal file
17
event-manager/.env.sample
Normal file
@@ -0,0 +1,17 @@
|
||||
# DISCORD BOT TOKEN
|
||||
# MUST HAVE PERMISSIONS TO CREATE EVENTS & MANAGE EVENTS
|
||||
# https://discord.com/developers/applications
|
||||
|
||||
export DISCORD_BOT_TOKEN = "TOKEN"
|
||||
|
||||
# -----------
|
||||
|
||||
# DISCORD SERVER ID (GUILD ID)
|
||||
# developersIndia => 1229786646468362260
|
||||
export DISCORD_GUILD_ID = 1229786646468362260
|
||||
|
||||
# -----------
|
||||
|
||||
# CALANDER ID
|
||||
# developersIndia => "9f1337e4154910eb1bdb3bfac32b88f69546468b1281a6db58f50a909df5049f@group.calendar.google.com"
|
||||
export GOOGLE_CALENDAR_ID = "9f1337e4154910eb1bdb3bfac32b88f69546468b1281a6db58f50a909df5049f@group.calendar.google.com"
|
52
event-manager/README.md
Normal file
52
event-manager/README.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# Automation to create events across Google Calendar & Discord
|
||||
|
||||
|
||||
## Description
|
||||
|
||||
This script creates events across [Google Calendar](https://developersindia.in/events-calendar/) & [Discord](https://discord.com/channels/669880381649977354/)
|
||||
|
||||
### First Time Setup
|
||||
|
||||
1. Get Python3
|
||||
|
||||
```bash
|
||||
sudo apt-get install python3 && python3 --version
|
||||
```
|
||||
|
||||
2. Install required packages
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
3. Add respective tokens in the `.env` file
|
||||
|
||||
```bash
|
||||
cp .sample.env .env
|
||||
```
|
||||
|
||||
1. `DISCORD_BOT_TOKEN`
|
||||
- Get it from [Discord Developers portal](https://discord.com/developers/applications/)) (bot must have MANAGE_EVENT & CREATE_EVENT permission)
|
||||
|
||||
2. `DISCORD_GUILD_ID`
|
||||
- developersIndia's GUID is `1229786646468362260`
|
||||
|
||||
3. `GOOGLE_CALENDAR_ID`
|
||||
- developersIndia calendar is public, `9f1337e4154910eb1bdb3bfac32b88f69546468b1281a6db58f50a909df5049f@group.calendar.google.com`
|
||||
|
||||
4. Connect Google calendar through [Google cloud Console](https://console.cloud.google.com/)
|
||||
1. 4.1 Create a Project on Google Cloud Console
|
||||
2. Search for calendar API and enable it
|
||||
3. Create Credentials -> OAuth Client ID -> Application type as Desktop
|
||||
4. Download the JSON file
|
||||
5. Rename that JSON file as `credentials.json` and save it to the project directory.
|
||||
|
||||
5. `python3 main.py`
|
||||
|
||||
---
|
||||
|
||||
### NOTES-
|
||||
|
||||
> - Google authenication is required for the first time.
|
||||
>
|
||||
> - A file `token.json` will be downloaded automatically, and no web login will be needed afterwards.
|
57
event-manager/discord_bot.py
Normal file
57
event-manager/discord_bot.py
Normal file
@@ -0,0 +1,57 @@
|
||||
from datetime import datetime, timedelta
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
|
||||
|
||||
def create_discord_event(
|
||||
bot_token,
|
||||
guild_id,
|
||||
EVENT_NAME,
|
||||
EVENT_DESCRIPTION,
|
||||
EVENT_LOCATION,
|
||||
EVENT_DATE,
|
||||
EVENT_START_TIME,
|
||||
EVENT_END_TIME,
|
||||
):
|
||||
|
||||
bot = commands.Bot(command_prefix="!", intents=discord.Intents.default())
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
|
||||
# Convert the date string to a datetime object
|
||||
date_object = datetime.strptime(EVENT_DATE, "%Y-%m-%d")
|
||||
|
||||
# Convert the time string to a datetime object
|
||||
start_time_object = datetime.strptime(EVENT_START_TIME, "%H:%M")
|
||||
end_time_object = datetime.strptime(EVENT_END_TIME, "%H:%M")
|
||||
|
||||
# Combine the date and time objects
|
||||
st = date_object.replace(
|
||||
hour=start_time_object.hour, minute=start_time_object.minute
|
||||
).astimezone()
|
||||
et = date_object.replace(
|
||||
hour=end_time_object.hour, minute=end_time_object.minute
|
||||
).astimezone()
|
||||
|
||||
gg = bot.get_guild(guild_id)
|
||||
|
||||
try:
|
||||
event = await gg.create_scheduled_event(
|
||||
name=EVENT_NAME,
|
||||
entity_type=discord.EntityType.external,
|
||||
description=EVENT_DESCRIPTION,
|
||||
start_time=st,
|
||||
end_time=et,
|
||||
location=EVENT_LOCATION,
|
||||
privacy_level=discord.PrivacyLevel.guild_only,
|
||||
)
|
||||
print("Discord Event created: ", event.url)
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
await bot.close()
|
||||
|
||||
# Run the bot
|
||||
bot.run(bot_token)
|
58
event-manager/google_calendar.py
Normal file
58
event-manager/google_calendar.py
Normal file
@@ -0,0 +1,58 @@
|
||||
import os.path
|
||||
|
||||
from google.auth.transport.requests import Request
|
||||
from google.oauth2.credentials import Credentials
|
||||
from google_auth_oauthlib.flow import InstalledAppFlow
|
||||
from googleapiclient.discovery import build
|
||||
|
||||
SCOPES = ["https://www.googleapis.com/auth/calendar"]
|
||||
|
||||
|
||||
def create_google_calendar_event(
|
||||
calendar_id, name, description, location, date, start_time, end_time
|
||||
):
|
||||
|
||||
creds = None
|
||||
|
||||
# The file token.json stores the user's access and refresh tokens
|
||||
if os.path.exists("token.json"):
|
||||
creds = Credentials.from_authorized_user_file("token.json", SCOPES)
|
||||
|
||||
# If there are no (valid) credentials available, let the user log in.
|
||||
if not creds or not creds.valid:
|
||||
if creds and creds.expired and creds.refresh_token:
|
||||
creds.refresh(Request())
|
||||
else:
|
||||
print("Login to your Google account. [THIS IS A ONE TIME PROCESS]")
|
||||
flow = InstalledAppFlow.from_client_secrets_file("credentials.json", SCOPES)
|
||||
creds = flow.run_local_server(port=0)
|
||||
# Save the credentials for the next run
|
||||
with open("token.json", "w") as token:
|
||||
token.write(creds.to_json())
|
||||
|
||||
try:
|
||||
service = build("calendar", "v3", credentials=creds)
|
||||
start = f"{date}T{start_time}:00"
|
||||
end = f"{date}T{end_time}:00"
|
||||
event = {
|
||||
"summary": name,
|
||||
"location": location,
|
||||
"description": description,
|
||||
"start": {
|
||||
"dateTime": start,
|
||||
"timeZone": "Asia/Kolkata",
|
||||
},
|
||||
"end": {
|
||||
"dateTime": end,
|
||||
"timeZone": "Asia/Kolkata",
|
||||
},
|
||||
}
|
||||
|
||||
event = service.events().insert(calendarId=calendar_id, body=event).execute()
|
||||
|
||||
print("Calendar event created: %s" % (event.get("htmlLink")))
|
||||
return event
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return None
|
29
event-manager/main.py
Normal file
29
event-manager/main.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
bot_token = os.getenv('DISCORD_BOT_TOKEN')
|
||||
guild_id = int(os.getenv('DISCORD_GUILD_ID'))
|
||||
calendar_id = os.getenv('GOOGLE_CALENDAR_ID')
|
||||
|
||||
def get_input():
|
||||
NAME = input("Event title: ")
|
||||
DESCRIPTION = input("Event description: ")
|
||||
LOCATION = input("Event location (red -> for developersindia subreddit): ")
|
||||
if LOCATION == "red":
|
||||
LOCATION = "https://www.reddit.com/r/developersindia/"
|
||||
DATE = input("Enter the event date (yyyy-mm-dd): ")
|
||||
START_TIME = input("Enter the event start time (hh:mm)- ")
|
||||
END_TIME = input("Enter the event end time (hh:mm)- ")
|
||||
|
||||
return NAME, DESCRIPTION, LOCATION, DATE, START_TIME, END_TIME
|
||||
|
||||
EVENT_NAME, EVENT_DESCRIPTION, EVENT_LOCATION, EVENT_DATE, EVENT_START_TIME, EVENT_END_TIME = get_input()
|
||||
|
||||
# Execute create_discord_event
|
||||
from discord_bot import create_discord_event
|
||||
create_discord_event(bot_token, guild_id, EVENT_NAME, EVENT_DESCRIPTION, EVENT_LOCATION, EVENT_DATE, EVENT_START_TIME, EVENT_END_TIME)
|
||||
|
||||
# Execute google_calendar_event
|
||||
from google_calendar import create_google_calendar_event
|
||||
create_google_calendar_event(calendar_id, EVENT_NAME, EVENT_DESCRIPTION, EVENT_LOCATION, EVENT_DATE, EVENT_START_TIME, EVENT_END_TIME)
|
5
event-manager/requirements.txt
Normal file
5
event-manager/requirements.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
discord.py
|
||||
google-api-python-client
|
||||
google-auth-httplib2
|
||||
google-auth-oauthlib
|
||||
python-dotenv
|
@@ -2,28 +2,22 @@
|
||||
"titles": [
|
||||
"wrestling with Jira",
|
||||
"trapped in endless meetings",
|
||||
"exterminating code critters",
|
||||
"centering divs for fun",
|
||||
"impatiently waiting on staging",
|
||||
"crafting elegant tests",
|
||||
"yolo pushing to prod",
|
||||
"code review detectives",
|
||||
"assassinating Jira tickets",
|
||||
"forging majestic pull requests",
|
||||
"DB migration amnesiacs",
|
||||
"lgtm",
|
||||
"LGTM",
|
||||
"staging environment warriors",
|
||||
"taming wild git branches",
|
||||
"unleashing the MVP",
|
||||
"Jira ticket treasure hunters",
|
||||
"jira ticket treasure hunters",
|
||||
"merge conflict negotiators",
|
||||
"absorbing knowledge transfer",
|
||||
"absorbing KTs",
|
||||
"purging container hoarders",
|
||||
"bug creators and breadwinners",
|
||||
"DSA explorers",
|
||||
"escaping Vim's clutches",
|
||||
"indexing database maestros",
|
||||
"YAML whisperers",
|
||||
"debugging code in dreams",
|
||||
"refactoring like it's an art",
|
||||
"living on Stack Overflow",
|
||||
@@ -42,6 +36,13 @@
|
||||
"refining their Google-fu",
|
||||
"upgrading their tech stacks",
|
||||
"writing self-documenting code",
|
||||
"drowning in technical debt"
|
||||
"drowning in technical debt",
|
||||
"stuck on git merge",
|
||||
"asking for PR reviews",
|
||||
"finding DB backups",
|
||||
"venting about YAML",
|
||||
"not writing unit tests",
|
||||
"writing unit tests",
|
||||
"think TDD is a joke"
|
||||
]
|
||||
}
|
||||
|
@@ -23,13 +23,13 @@ class Config:
|
||||
SUBREDDIT = "developersindia"
|
||||
|
||||
POST_FLAIR = "Hiring"
|
||||
POST_TITLE = f"Don't Miss Out on These Job Opportunities | Weekly Job Openings Thread | {strftime(STRFTIME_FORMAT)}"
|
||||
POST_TITLE = f"Don't Miss Out on These Job Opportunities | Job Openings Mega-thread | {strftime(STRFTIME_FORMAT)}"
|
||||
POST_TEXT = """\
|
||||
This thread has all the latest job openings that haven't been posted on previous weekly threads.
|
||||
This thread has all the latest job openings that haven't been posted on previous hiring mega threads.
|
||||
|
||||
If you have a job opening that you'd like to share with the community, you can post it using this link:- https://developersindia.in/post-a-job/
|
||||
|
||||
For all the available job openings, check out the Job Board at:- https://developersindia.in/job-board/
|
||||
- If you have a job opening that you'd like to share with the community, you can post it using [this link](https://developersindia.in/post-a-job/).
|
||||
- For all the available job openings, check out our [Job Board](https://developersindia.in/job-board/).
|
||||
- If you are looking for work, consider participating in our monthly ["Hire Me" megathreads](https://www.reddit.com/r/developersIndia/?f=flair_name%3A%22Hire%20Me%22).
|
||||
|
||||
Stay tuned for updates on the latest job openings, and apply for the ones that interest you. Wishing you the best of luck in your job search!\
|
||||
"""
|
||||
|
@@ -28,11 +28,13 @@ def create_showcase_sunday_megathread(subreddit):
|
||||
|
||||
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.
|
||||
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. Ask for feedback, and help each other out.
|
||||
|
||||
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.
|
||||
|
||||
**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).**
|
||||
### [Looking for more projects built by developersIndia community members?](https://www.reddit.com/r/developersIndia/?f=flair_name%3A%22I%20Made%20This%20%3Asnoo_wink%3A%22)
|
||||
|
||||
**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). You can also find past [showcase sunday megathreads here](https://www.reddit.com/r/developersIndia/?f=flair_name%3A%22Showcase%20Sunday%20%3Asnoo_hearteyes%3A%22)**.
|
||||
"""
|
||||
|
||||
submission = subreddit.submit(
|
||||
|
@@ -75,7 +75,7 @@ old_flairs_total_count = sum(old_available_flair_count.values())
|
||||
# print(f"Total count of user-flairs: {total_count + emoji_flair_count + old_flairs_total_count}")
|
||||
|
||||
data = {
|
||||
'Users with un-supported (old) text flairs': f"**{old_flairs_total_count}**",
|
||||
'Users with custom text flairs': f"**{old_flairs_total_count}**",
|
||||
'Users with supported text flairs': f"**{total_count}**",
|
||||
'Users with emoji only flairs': f"**{emoji_flair_count}**",
|
||||
'Total count of user-flairs': f"**{total_count + emoji_flair_count + old_flairs_total_count}**"
|
||||
|
60
wiki-mention/main.py
Normal file
60
wiki-mention/main.py
Normal file
@@ -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 contribution by searching your username in the [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. If you have any questions/concerns feel free to reply to this mail or create a new modmail.\n\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()
|
Reference in New Issue
Block a user