Scrape latest data #21817
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Scrape latest data | |
on: | |
push: | |
workflow_dispatch: | |
schedule: | |
- cron: '*/10 * * * *' | |
env: | |
ACCEPT_LANG: 'Accept-Language: ivl-IV' | |
CLIENT: 'X-Super-Client: ${{ github.repository }}' | |
CONTACT: 'X-Super-Contact: ${{ github.repository_owner }}' | |
jobs: | |
scheduled: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out this repo | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 1440 | |
- name: Setup node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
cache: "npm" | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
cache: "pip" | |
- name: Install node dependencies | |
run: npm ci | |
- name: Install Python requirements | |
run: |- | |
python -m pip install -U pip | |
pip install -r requirements.txt | |
- name: Fetch latest data | |
run: |- | |
curl -A "${{github.repository}}" -H "${{env.ACCEPT_LANG}}" -H "${{env.CLIENT}}" -H "${{env.CONTACT}}" https://api.helldivers2.dev/api/v1/war -o 801_war_v1.json | |
curl -A "${{github.repository}}" -H "${{env.ACCEPT_LANG}}" -H "${{env.CLIENT}}" -H "${{env.CONTACT}}" https://api.helldivers2.dev/api/v1/planets -o 801_planets_v1.json | |
curl -A "${{github.repository}}" -H "${{env.ACCEPT_LANG}}" -H "${{env.CLIENT}}" -H "${{env.CONTACT}}" https://api.helldivers2.dev/api/v1/assignments -o 801_assignments_v1.json | |
curl -A "${{github.repository}}" -H "${{env.ACCEPT_LANG}}" -H "${{env.CLIENT}}" -H "${{env.CONTACT}}" https://api.helldivers2.dev/api/v1/campaigns -o 801_campaigns_v1.json | |
curl -A "${{github.repository}}" -H "${{env.ACCEPT_LANG}}" -H "${{env.CLIENT}}" -H "${{env.CONTACT}}" https://api.helldivers2.dev/api/v1/dispatches -o 801_dispatches_v1.json | |
jq -s "{war:.[0],planets:.[1],assignments:.[2],campaigns:.[3],dispatches:.[4]}" 801_war_v1.json 801_planets_v1.json 801_assignments_v1.json 801_campaigns_v1.json 801_dispatches_v1.json > 801_full_v1.json | |
- name: Commit and push if it changed | |
run: |- | |
git config user.name "Automated" | |
git config user.email "[email protected]" | |
git add helldivers.json 801_full_v1.json | |
timestamp=$(date -u) | |
git commit -m "Latest data: ${timestamp}" || exit 0 | |
git push | |
- name: Generate aggregate stats | |
run: |- | |
if ! jq -e 'has("errors")' helldivers.json > /dev/null && ! jq -e 'has("error")' helldivers.json > /dev/null ; then cp helldivers.json ./docs/data/helldivers.json ; fi | |
python3 build_stats.py | |
- name: Build | |
run: npm run build | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: ./dist | |
deploy: | |
needs: scheduled | |
permissions: | |
pages: write | |
id-token: write | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 |