mirror of
https://github.com/developersIndia/deviras.git
synced 2025-05-31 14:11:43 +05:30
Compare commits
6 Commits
a73d956b23
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
3feccf6755 | ||
|
101b529307 | ||
|
e9a454fa5a | ||
|
345dc1016e | ||
|
2824227ac9 | ||
|
e84b1b18ae |
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
|
||||
|
13
aoc/main.py
13
aoc/main.py
@@ -10,9 +10,9 @@ user_agent = 'AdventOfCode Leaderboard Updater - developersIndia'
|
||||
aoc_session_cookie = os.environ["AOC_SESSION_COOKIE"]
|
||||
aoc_leaderboard_code = os.environ["AOC_LEADERBOARD_CODE"]
|
||||
aoc_year = os.environ.get("AOC_YEAR")
|
||||
reddit_post_id = os.environ.get("REDDIT_POST_ID")
|
||||
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=aoc_year), cookies={'session': aoc_session_cookie})
|
||||
@@ -31,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/{aoc_year}/leaderboard/private/view/{aoc_leaderboard_code})\n"
|
||||
leaderboard_stats += f"\nUpdated every 24 hours"
|
||||
|
||||
return leaderboard_stats
|
||||
@@ -44,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(
|
||||
@@ -56,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.
|
||||
|
||||

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

|
||||
|
@@ -154,6 +154,7 @@ 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|Announcements from volunteer team|\n|--------|\n"
|
||||
|
Reference in New Issue
Block a user