Skip to content

Commit

Permalink
Add script to automate updating warships.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Rukenshia committed Feb 19, 2023
1 parent 1b73fa9 commit 1b9b9dc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
warships.json
12 changes: 12 additions & 0 deletions data/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# get cloudfront distribution id for data.shipvote.in.fkn.space
DISTRIBUTION_ID=$(shell aws cloudfront list-distributions | jq -r '.DistributionList.Items[] | select(.Origins.Items[].DomainName == "data.shipvote.in.fkn.space.s3.amazonaws.com") | .Id')


.PHONY: all
all:
./get_warships.sh

aws s3 cp ./warships.json s3://data.shipvote.in.fkn.space/warships.json

# create invalidation for cloudfront
aws cloudfront create-invalidation --distribution-id ${DISTRIBUTION_ID} --paths /shipvote/*
28 changes: 28 additions & 0 deletions data/get_warships.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
set -eo pipefail

get_page_meta() {
curl -s "https://api.worldofwarships.eu/wows/encyclopedia/ships/?application_id=80aa6f7e1d5df049c79d9141dd0826ae&limit=100" | jq '.meta'
}

get_page() {
curl -s "https://api.worldofwarships.eu/wows/encyclopedia/ships/?application_id=80aa6f7e1d5df049c79d9141dd0826ae&fields=name,nation,ship_id,type,tier,images.small&limit=100&page_no=${1}" | jq '.data | to_entries | map(.value)'
}

max_page="$(get_page_meta | jq '.page_total')"

ships="[]"

for p in $(seq 1 ${max_page}); do
current_page="$(get_page "$p")"

ships="$(jq -rnc --argjson current "${ships}" --argjson new "${current_page}" '$current + $new')"
done

# rename ship_id to id
ships="$(jq -rnc --argjson ships "${ships}" '$ships | map(. + {id: .ship_id}) | map(del(.ship_id))')"

# flatten images.small to image
ships="$(jq -rnc --argjson ships "${ships}" '$ships | map(. + {image: .images.small}) | map(del(.images))')"

echo "${ships}" > warships.json

0 comments on commit 1b9b9dc

Please sign in to comment.