-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to automate updating warships.json
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 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 @@ | ||
warships.json |
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,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/* |
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,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 |