Skip to content

Commit e84b1b1

Browse files
committed
fix env reference
1 parent a73d956 commit e84b1b1

File tree

3 files changed

+46
-50
lines changed

3 files changed

+46
-50
lines changed

.github/workflows/aoc.yml

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
1-
name : AoC leaderboard
1+
name: AoC leaderboard
22

33
on:
4-
# schedule:
5-
# Every 2 hours”
6-
# - cron: '0 */2 * * *'
7-
workflow_dispatch:
4+
schedule:
5+
# Run every 24 hours at 00:00 UTC
6+
- cron: "0 0 * * *"
7+
workflow_dispatch:
88

99
permissions:
1010
contents: read
1111

1212
jobs:
13-
build:
14-
runs-on: ubuntu-latest
13+
build:
14+
runs-on: ubuntu-latest
1515

16-
steps:
17-
- uses: actions/checkout@v3
18-
- name: Set up Python 3.10
19-
uses: actions/setup-python@v3
20-
with:
21-
python-version: "3.10"
22-
- name: Install dependencies
23-
run: |
24-
python -m pip install --upgrade pip
25-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
26-
- name: Update Learderboard
27-
env:
28-
REDDIT_CLIENT_ID: ${{ secrets.REDDIT_CLIENT_ID }}
29-
REDDIT_CLIENT_SECRET: ${{ secrets.REDDIT_CLIENT_SECRET }}
30-
REDDIT_PASSWORD: ${{ secrets.REDDIT_PASSWORD }}
31-
REDDIT_USERNAME: ${{ secrets.REDDIT_USERNAME }}
32-
AOC_SESSION_COOKIE: ${{ secrets.AOC_SESSION_COOKIE }}
33-
AOC_LEADERBOARD_CODE: ${{ secrets.AOC_LEADERBOARD_CODE }}
34-
REDDIT_POST_ID: ${{ secrets.REDDIT_POST_ID }}
35-
run: |
36-
cd aoc
37-
python main.py
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Set up Python 3.10
19+
uses: actions/setup-python@v3
20+
with:
21+
python-version: "3.10"
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
26+
- name: Update Leaderboard
27+
env:
28+
REDDIT_CLIENT_ID: ${{ secrets.REDDIT_CLIENT_ID }}
29+
REDDIT_CLIENT_SECRET: ${{ secrets.REDDIT_CLIENT_SECRET }}
30+
REDDIT_PASSWORD: ${{ secrets.REDDIT_PASSWORD }}
31+
REDDIT_USERNAME: ${{ secrets.REDDIT_USERNAME }}
32+
AOC_SESSION_COOKIE: ${{ secrets.AOC_SESSION_COOKIE }}
33+
AOC_LEADERBOARD_CODE: ${{ secrets.AOC_LEADERBOARD_CODE }}
34+
AOC_LEADERBOARD_REDDIT_POST_ID: ${{ secrets.AOC_LEADERBOARD_REDDIT_POST_ID }}
35+
AOC_YEAR: ${{ secrets.AOC_YEAR }}
36+
run: |
37+
cd aoc
38+
python main.py

aoc/main.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
aoc_session_cookie = os.environ["AOC_SESSION_COOKIE"]
1111
aoc_leaderboard_code = os.environ["AOC_LEADERBOARD_CODE"]
1212
aoc_year = os.environ.get("AOC_YEAR")
13-
reddit_post_id = os.environ.get("REDDIT_POST_ID")
13+
reddit_post_id = os.environ.get("AOC_LEADERBOARD_REDDIT_POST_ID")
1414

15-
aoc_url = f'https://adventofcode.com/{{year}}/leaderboard/private/view/{aoc_leaderboard_code}.json'
15+
aoc_url = f'https://adventofcode.com/{aoc_year}/leaderboard/private/view/{aoc_leaderboard_code}.json'
1616

1717
def get_leaderboard_data():
1818
response = requests.get(aoc_url.format(year=aoc_year), cookies={'session': aoc_session_cookie})
@@ -44,7 +44,7 @@ def update_reddit_post(reddit, post_id, new_stats):
4444

4545
def main():
4646
if not reddit_post_id:
47-
print("Please set the REDDIT_POST_ID environment variable.")
47+
print("Please set the AOC_LEADERBOARD_REDDIT_POST_ID environment variable.")
4848
return
4949

5050
reddit = praw.Reddit(
@@ -56,9 +56,7 @@ def main():
5656
)
5757

5858
leaderboard_data = get_leaderboard_data()
59-
6059
formatted_stats = format_leaderboard(leaderboard_data)
61-
6260
update_reddit_post(reddit, reddit_post_id, formatted_stats)
6361

6462
if __name__ == "__main__":

aoc/readme.md

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
# AoC Private Leaderboard Stats Updater Script for Reddit
22

3-
## Required Environment Variables
3+
## Required Environment Variables
44

5-
6-
1. `REDDIT_CLIENT_ID`: Reddit API client ID.
7-
2. `REDDIT_CLIENT_SECRET`: Reddit API client secret.
8-
3. `REDDIT_PASSWORD`: Reddit account password.
9-
4. `REDDIT_USERNAME`: Reddit account username.
10-
5. `AOC_SESSION_COOKIE`: Session cookie for the Advent of Code website.
11-
6. `AOC_LEADERBOARD_CODE`: Code for the Advent of Code leaderboard.
12-
7. `REDDIT_POST_ID`: ID of Reddit post which is used as leaderboard.
5+
1. `REDDIT_CLIENT_ID`: Reddit API client ID.
6+
2. `REDDIT_CLIENT_SECRET`: Reddit API client secret.
7+
3. `REDDIT_PASSWORD`: Reddit account password.
8+
4. `REDDIT_USERNAME`: Reddit account username.
9+
5. `AOC_SESSION_COOKIE`: Session cookie for the Advent of Code website.
10+
6. `AOC_LEADERBOARD_CODE`: Code for the Advent of Code leaderboard.
11+
7. `AOC_LEADERBOARD_REDDIT_POST_ID`: ID of Reddit post which is used as leaderboard.
1312

1413
----
14+
1515
## Instructions on how to get `AOC_SESSION_COOKIE`
16+
1617
1. **Create an Advent of Code Account:**
1718
- 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.
1819

1920
2. **Log into Your AoC Account & open the leaderboard**
2021
- 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.
21-
22+
2223
3. **Open Developer Tools in Your Browser:**
2324
- 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.
24-
25+
2526
4. **Go to the Network Tab:**
2627
- In the developer tools, go to the "Network" tab. This tab will show all network requests made by the website.
2728

@@ -41,8 +42,4 @@
4142
9. **Use the Session Cookie:**
4243
- 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.
4344

44-
![session-cookie](https://github.com/ni5arga/deviras/blob/main/aoc/cookie.png?raw=true)
45-
46-
47-
48-
45+
![session-cookie](https://raw.githubusercontent.com/developersindia/deviras/refs/heads/main/aoc/cookie.png)

0 commit comments

Comments
 (0)