-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (52 loc) · 2.2 KB
/
Copy pathcacheApiData.yml
File metadata and controls
63 lines (52 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
name: Poll Helldivers API and Cache Data
on:
schedule:
# Runs at every 15th minute
- cron: '*/15 * * * *'
jobs:
cache-planet-data:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install jq for JSON parsing
run: sudo apt-get install jq
- name: Move newData files older than 24 hours to 24hourData
run: |
mkdir -p newData 24hourData
current_time=$(date -u +%s)
# Loop through each file in the newData directory
for file in newData/*_campaigns.json; do
filename=$(basename "$file")
timestamp="${filename:0:20}" # Extracts 'YYYY-MM-DDTHH:MM:SS'
file_time=$(date -u -d "$timestamp" +%s)
diff=$(( (current_time - file_time) / 3600 ))
# Move files older than 24 hours to 24hourData
if [ "$diff" -gt 24 ]; then
echo "Moving $file to 24hourData (older than 24 hours)"
mv "$file" "24hourData/"
fi
done
- name: Cleanup files older than 24 hours in 24hourData
run: |
current_time=$(date -u +%s)
# Loop through each file in the 24hourData directory
for file in 24hourData/*_campaigns.json; do
filename=$(basename "$file")
timestamp="${filename:0:20}" # Extracts 'YYYY-MM-DDTHH:MM:SS'
file_time=$(date -u -d "$timestamp" +%s)
diff=$(( (current_time - file_time) / 3600 ))
# Delete files older than 48 hours
if [ "$diff" -gt 48 ]; then
echo "Deleting $file (older than 48 hours)"
rm "$file"
fi
done
- name: Commit and push if there are changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Actions Bot"
git add newData/ 24hourData/
git commit -m "Clean old data" -a || echo "No changes to commit"
git remote set-url origin https://x-access-token:${{ secrets.ACTION_BOT_KEY }}@github.com/devpoole2907/helldivers-api-cache.git
git push