mirror of
https://github.com/developersIndia/deviras.git
synced 2024-12-22 16:19:50 +05:30
fix env reference
This commit is contained in:
parent
a73d956b23
commit
e84b1b18ae
59
.github/workflows/aoc.yml
vendored
59
.github/workflows/aoc.yml
vendored
@ -1,37 +1,38 @@
|
|||||||
name : AoC leaderboard
|
name: AoC leaderboard
|
||||||
|
|
||||||
on:
|
on:
|
||||||
# schedule:
|
schedule:
|
||||||
# Every 2 hours”
|
# Run every 24 hours at 00:00 UTC
|
||||||
# - cron: '0 */2 * * *'
|
- cron: "0 0 * * *"
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Set up Python 3.10
|
- name: Set up Python 3.10
|
||||||
uses: actions/setup-python@v3
|
uses: actions/setup-python@v3
|
||||||
with:
|
with:
|
||||||
python-version: "3.10"
|
python-version: "3.10"
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
||||||
- name: Update Learderboard
|
- name: Update Leaderboard
|
||||||
env:
|
env:
|
||||||
REDDIT_CLIENT_ID: ${{ secrets.REDDIT_CLIENT_ID }}
|
REDDIT_CLIENT_ID: ${{ secrets.REDDIT_CLIENT_ID }}
|
||||||
REDDIT_CLIENT_SECRET: ${{ secrets.REDDIT_CLIENT_SECRET }}
|
REDDIT_CLIENT_SECRET: ${{ secrets.REDDIT_CLIENT_SECRET }}
|
||||||
REDDIT_PASSWORD: ${{ secrets.REDDIT_PASSWORD }}
|
REDDIT_PASSWORD: ${{ secrets.REDDIT_PASSWORD }}
|
||||||
REDDIT_USERNAME: ${{ secrets.REDDIT_USERNAME }}
|
REDDIT_USERNAME: ${{ secrets.REDDIT_USERNAME }}
|
||||||
AOC_SESSION_COOKIE: ${{ secrets.AOC_SESSION_COOKIE }}
|
AOC_SESSION_COOKIE: ${{ secrets.AOC_SESSION_COOKIE }}
|
||||||
AOC_LEADERBOARD_CODE: ${{ secrets.AOC_LEADERBOARD_CODE }}
|
AOC_LEADERBOARD_CODE: ${{ secrets.AOC_LEADERBOARD_CODE }}
|
||||||
REDDIT_POST_ID: ${{ secrets.REDDIT_POST_ID }}
|
AOC_LEADERBOARD_REDDIT_POST_ID: ${{ secrets.AOC_LEADERBOARD_REDDIT_POST_ID }}
|
||||||
run: |
|
AOC_YEAR: ${{ secrets.AOC_YEAR }}
|
||||||
cd aoc
|
run: |
|
||||||
python main.py
|
cd aoc
|
||||||
|
python main.py
|
||||||
|
@ -10,9 +10,9 @@ user_agent = 'AdventOfCode Leaderboard Updater - developersIndia'
|
|||||||
aoc_session_cookie = os.environ["AOC_SESSION_COOKIE"]
|
aoc_session_cookie = os.environ["AOC_SESSION_COOKIE"]
|
||||||
aoc_leaderboard_code = os.environ["AOC_LEADERBOARD_CODE"]
|
aoc_leaderboard_code = os.environ["AOC_LEADERBOARD_CODE"]
|
||||||
aoc_year = os.environ.get("AOC_YEAR")
|
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():
|
def get_leaderboard_data():
|
||||||
response = requests.get(aoc_url.format(year=aoc_year), cookies={'session': aoc_session_cookie})
|
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):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
if not reddit_post_id:
|
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
|
return
|
||||||
|
|
||||||
reddit = praw.Reddit(
|
reddit = praw.Reddit(
|
||||||
@ -56,9 +56,7 @@ def main():
|
|||||||
)
|
)
|
||||||
|
|
||||||
leaderboard_data = get_leaderboard_data()
|
leaderboard_data = get_leaderboard_data()
|
||||||
|
|
||||||
formatted_stats = format_leaderboard(leaderboard_data)
|
formatted_stats = format_leaderboard(leaderboard_data)
|
||||||
|
|
||||||
update_reddit_post(reddit, reddit_post_id, formatted_stats)
|
update_reddit_post(reddit, reddit_post_id, formatted_stats)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -2,17 +2,18 @@
|
|||||||
|
|
||||||
## Required Environment Variables
|
## Required Environment Variables
|
||||||
|
|
||||||
|
1. `REDDIT_CLIENT_ID`: Reddit API client ID.
|
||||||
1. `REDDIT_CLIENT_ID`: Reddit API client ID.
|
2. `REDDIT_CLIENT_SECRET`: Reddit API client secret.
|
||||||
2. `REDDIT_CLIENT_SECRET`: Reddit API client secret.
|
3. `REDDIT_PASSWORD`: Reddit account password.
|
||||||
3. `REDDIT_PASSWORD`: Reddit account password.
|
4. `REDDIT_USERNAME`: Reddit account username.
|
||||||
4. `REDDIT_USERNAME`: Reddit account username.
|
5. `AOC_SESSION_COOKIE`: Session cookie for the Advent of Code website.
|
||||||
5. `AOC_SESSION_COOKIE`: Session cookie for the Advent of Code website.
|
6. `AOC_LEADERBOARD_CODE`: Code for the Advent of Code leaderboard.
|
||||||
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.
|
||||||
7. `REDDIT_POST_ID`: ID of Reddit post which is used as leaderboard.
|
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
## Instructions on how to get `AOC_SESSION_COOKIE`
|
## Instructions on how to get `AOC_SESSION_COOKIE`
|
||||||
|
|
||||||
1. **Create an Advent of Code Account:**
|
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.
|
- 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.
|
||||||
|
|
||||||
@ -41,8 +42,4 @@
|
|||||||
9. **Use the Session Cookie:**
|
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.
|
- 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.
|
||||||
|
|
||||||
![session-cookie](https://github.com/ni5arga/deviras/blob/main/aoc/cookie.png?raw=true)
|
![session-cookie](https://raw.githubusercontent.com/developersindia/deviras/refs/heads/main/aoc/cookie.png)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user