Created
March 16, 2022 20:07
-
-
Save quiiver/b75d190b0346084de4d3e97495cf8463 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
top=$(mktemp) | |
tmp1=$(mktemp) | |
tmp2=$(mktemp) | |
i=1 | |
while [[ $(jq 'keys | length' $top) -lt 5000 ]]; do | |
echo iteration $i - $(jq 'keys | length' $top) | |
d=$(date -v-${i}d '+%Y/%m/%d') | |
url="https://wikimedia.org/api/rest_v1/metrics/pageviews/top/en.wikipedia.org/desktop/${d}" | |
curl -s -X 'GET' \ | |
$url \ | |
-H 'accept: application/json' \ | |
| jq "[.items[].articles[] | {(.article): {\"${d}\": { views:.views, rank:.rank }}}] | add" > $tmp1 | |
if [[ $i == 1 ]]; then | |
cat $tmp1 > $top | |
else | |
cat $top > $tmp2 | |
jq -s '.[0] * .[1]' $tmp2 $tmp1 > $top | |
fi | |
i=$((i+1)) | |
done | |
echo $top | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment