nullpot
12/19/2014 - 4:42 AM

自分の書いたgistのIDを全部抽出

自分の書いたgistのIDを全部抽出

#!/bin/bash
# input token / username
token="usertoken"
username="username"

# get lastpage
page_last=`curl -i -s -u $token:x-oauth-basic https://api.github.com/users/$username/gists?page=1 | grep Link: | grep 'rel="last"' | tr "," "\n" | grep last | tr ">" "\n" | head -n 1 | tr "=" "\n" | tail -n 1`

# get all to file:result
rm -f result && touch result
for (( i = 1; i <= $page_last; i++ )); do curl -s -u $token:x-oauth-basic https://api.github.com/users/$username/gists?page=$i >> result
done

# using jq.
# To extract the necessary information from JSON
cat result | jq "map(.id)" | grep '"' | sed 's/[\,|"| ]//g' > tmp && mv tmp result

# view
cat result