Hourly Data Fetch #13883
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: Hourly Data Fetch | |
on: | |
push: | |
branches: [ main ] | |
schedule: | |
- cron: '*/5 * * * *' # Runs every hour | |
jobs: | |
fetch_data: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Setup Node.js environment | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '14' | |
- name: Fetch akiprices.json | |
run: | | |
echo "Fetching akiprices.json..." | |
curl -o akiprices.json https://dev.sp-tarkov.com/SPT-AKI/Server/raw/branch/master/project/assets/database/templates/prices.json | |
- name: Run fetch request and process data | |
run: | | |
echo "Running fetch request..." | |
DATA=$(curl -X POST https://api.tarkov.dev/graphql \ | |
-H "Content-Type: application/json" \ | |
-H "Accept: application/json" \ | |
-d '{ | |
"query": "{ items(type: any){ id avg24hPrice } }" | |
}') | |
echo "Processing data..." | |
PROCESSED_DATA=$(echo $DATA | node -e "\ | |
const fs = require('fs'); | |
const data = JSON.parse(fs.readFileSync(0, 'utf-8')); | |
const akiPrices = JSON.parse(fs.readFileSync('akiprices.json', 'utf-8')); | |
const processedData = {}; | |
data.data.items.forEach(item => { | |
if (akiPrices[item.id]) { | |
processedData[item.id] = item.avg24hPrice; | |
} | |
}); | |
console.log(JSON.stringify(processedData)); | |
") | |
echo $PROCESSED_DATA > prices.json | |
- name: Commit and push changes | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add prices.json | |
git commit -m "Update prices.json" | |
git push |