Fetch SteamDB Achievements #1
This file contains hidden or 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: Fetch SteamDB Achievements | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| fetch-achievements: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: 20 | |
| - name: Install dependencies | |
| run: | | |
| npm install axios fs-extra | |
| - name: Fetch game data from SteamDB | |
| env: | |
| STEAM_API_KEY: ${{ secrets.STEAM_API_KEY }} | |
| STEAM_ID: ${{ secrets.STEAM_ID }} | |
| run: | | |
| const fs = require('fs-extra'); | |
| const axios = require('axios'); | |
| (async () => { | |
| try { | |
| // Read AppIDs from manifest.json | |
| const manifestPath = 'AppID/manifest.json'; | |
| if (!fs.existsSync(manifestPath)) { | |
| console.error('manifest.json not found in AppID/'); | |
| process.exit(1); | |
| } | |
| const manifest = await fs.readJson(manifestPath); | |
| const appIds = manifest.appids || []; | |
| if (appIds.length === 0) { | |
| console.error('No AppIDs found in manifest.json'); | |
| process.exit(1); | |
| } | |
| for (let appId of appIds) { | |
| try { | |
| const storeData = await axios.get(`https://store.steampowered.com/api/appdetails?appids=${appId}`); | |
| const game = storeData.data[appId].data; | |
| const achievementsData = await axios.get(`https://steamdb.info/api/GetAchievements/?appid=${appId}`); | |
| const achievements = achievementsData.data || []; | |
| const htmlData = achievements.map(a => ` | |
| <div class=\"achievement ${a.achieved ? 'unlocked' : 'locked'}\"> | |
| <img src=\"${a.icon_url}\" class=\"achievement-icon\" /> | |
| <div class=\"achievement-info\"> | |
| <div class=\"achievement-name\">${a.name}</div> | |
| <div class=\"achievement-desc\">${a.description}</div> | |
| </div> | |
| </div> | |
| `).join(''); | |
| const gameHtml = ` | |
| <div class=\"game-card\"> | |
| <div class=\"game-header\"> | |
| <img src=\"${game.header_image}\" class=\"game-icon\" /> | |
| <div class=\"game-info\"> | |
| <div class=\"game-title\">${game.name}</div> | |
| <div class=\"game-appid\">AppID: ${appId}</div> | |
| </div> | |
| </div> | |
| <div class=\"achievements-list\">${htmlData}</div> | |
| </div>`; | |
| await fs.ensureDir('output'); | |
| await fs.writeFile(`output/game-${appId}.html`, gameHtml); | |
| } catch (e) { | |
| console.error('Error fetching AppID', appId, e.message); | |
| } | |
| } | |
| console.log('All games fetched successfully'); | |
| } catch (err) { | |
| console.error('Error reading manifest.json or fetching data:', err.message); | |
| process.exit(1); | |
| } | |
| })(); | |
| - name: Commit and push generated HTML | |
| run: | | |
| git config user.name 'github-actions' | |
| git config user.email 'github-actions@github.com' | |
| git add output/*.html | |
| git commit -m 'Add updated SteamDB achievement data' || echo 'No changes to commit' | |
| git push |