-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetArea.sh
More file actions
30 lines (29 loc) · 1.43 KB
/
getArea.sh
File metadata and controls
30 lines (29 loc) · 1.43 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
touch "rankingItems.json"
touch "ranking.json"
touch "rankingCountry.json"
touch "rankingCommunity.json"
touch "orgs.json"
[[ $(jq -e . <<< rankingItems.json >/dev/null 2>&1; echo $?) -ne 0 && $(cat rankingItems.json | jq 'length') -eq 0 ]] && {
echo "[]" > rankingItems.json
}
rankingItems=$(jq "." rankingItems.json)
for i in $(seq 0 1000);
do
response=$(curl -s --location 'https://api.btcmap.org/v3/areas/'$i'' --header 'Content-Type:application/json')
areaItem='{"id":'$i',"type":null,"merchantCount":0, "name": null}'
[[ $(jq -e . <<<"$response" >/dev/null 2>&1; echo $?) -eq 0 && $(echo "$response" | jq 'has("tags")' -r) = "true" ]] && {
areaItem=$(echo "$response" | jq 'del(.tags.geo_json)' | jq '.tags')
merchantCount=$(curl -s --location 'https://api.btcmap.org/rpc' --header 'Content-Type:application/json' --data '{"jsonrpc":"2.0","method":"get_area_dashboard","params":{"area_id":'$i'},"id":1}' | jq '.result.total_elements')
areaItemId=$(echo "$response" | jq '.id')
areaItem=$(echo "$areaItem" | jq '.id = '"$areaItemId"'')
areaItem=$(echo "$areaItem" | jq '.merchantCount = '"$merchantCount"'')
echo "$areaItem"
}
rankingItems=$(echo $rankingItems | jq '.['$i'] = '"$areaItem"'')
done
WORDCOUNT=$(echo "$rankingItems" | wc -w)
if [[ "$WORDCOUNT" -gt 10 ]]; then
echo "$rankingItems" > rankingItems.json
else
echo "The file does not have more than one line (it has 0 or 1 line)."
fi