-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add cron workflow to update external politician ranking
- Loading branch information
Showing
9 changed files
with
251 additions
and
24 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Update politician ranking | ||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 0 1 * *' | ||
jobs: | ||
update-ranking: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
cache: 'yarn' | ||
- name: Install dependencies | ||
run: yarn install | ||
- name: Test | ||
run: yarn test | ||
- name: Fetch politician ranking data | ||
run: yarn update:politician-ranking | ||
- name: Deploy to Github Page | ||
uses: JamesIves/github-pages-deploy-action@v4 | ||
with: | ||
folder: out | ||
commit-message: 'feat: update external politican ranking data' |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { HighlightedPolitician } from '$components/Index/StatCard.svelte'; | ||
import { existsSync, mkdirSync, writeFileSync } from 'fs'; | ||
import { join } from 'path'; | ||
import { getPoliticianWithMostViewLastMonth } from './wikipedia'; | ||
import { getPoliticianWithMostGun } from './gun'; | ||
import { fetchPoliticians } from '$lib/datasheets'; | ||
|
||
const OUT_DIR = './out'; | ||
const OUT_FILE = 'politician-ranking.json'; | ||
|
||
export interface RankingFile { | ||
politicianWithMostWikipediaVisit: Omit<HighlightedPolitician, 'reason'>; | ||
politicianWithMostGun: Omit<HighlightedPolitician, 'reason'>; | ||
updatedAt: Date; | ||
} | ||
|
||
export async function writePoliticianRankingFile() { | ||
console.info('Fetching politicians...'); | ||
const activePoliticians = (await fetchPoliticians()).filter(({ isActive }) => isActive); | ||
|
||
console.info('Fetching wikipedia views...'); | ||
const politicianWithMostWikipediaVisit = await getPoliticianWithMostViewLastMonth( | ||
activePoliticians | ||
); | ||
|
||
console.info('Fetching gun ownership...'); | ||
const politicianWithMostGun = await getPoliticianWithMostGun(activePoliticians); | ||
|
||
const rankingFile: RankingFile = { | ||
politicianWithMostWikipediaVisit, | ||
politicianWithMostGun, | ||
updatedAt: new Date() | ||
}; | ||
|
||
if (!existsSync(OUT_DIR)) mkdirSync(OUT_DIR); | ||
|
||
writeFileSync(join(OUT_DIR, OUT_FILE), JSON.stringify(rankingFile)); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { writePoliticianRankingFile } from '.'; | ||
|
||
writePoliticianRankingFile(); |
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
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
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
Oops, something went wrong.