2016-10-02 2 views
0

시간당 일일 커밋 수를 확인하고 싶습니다. 다음 명령을 사용하여 출력을 json 형식으로 가져올 수 있습니다. 그러나 명령 줄을 사용하여 json 형식의 값에 키를 추가 할 수 있는지 알고 싶습니다.힘내 통계 API JSON

curl https://api.github.com/repos/test/myrepo/stats/punch_card 

전류 출력 :

[ 
    0, 
    2, 
    32 
] 

예상 출력 :

은 "명령 줄"이외에는 아무 것도 지정하지 않은 때문에
[ 
    day: 0, 
    hour: 2, 
    commits: 32 
] 
+1

: // docs.ithithub.com/v3/repos/statistics/) 문서에 따르면 API는 해당 값과 함께 키를 방출하지 않습니다. –

답변

1

, 내가 있으리라 믿고있어 당신이 bash 기반을 원한다 해결책. 이 간단한 스크립트 (추한의 종류는하지만) 할 것입니다 당신이 원하는, (전체 응답의 닫는 대괄호에서 떨어져) 들여 쓰기를 유지하면서 : 아득히 [GitHub의의 API (HTTPS로

#!/bin/bash 

resp=$(curl https://api.github.com/repos/test/myrepo/stats/punch_card) 

nextPref="" 
for val in $resp 
do 
    echo "$nextPref $val" 
    if [[ $val == "[" && $nextPref == "" ]] 
    then 
     nextPref="  " 
    elif [[ $val == "[" && $nextPref == " " ]] 
    then 
     nextPref="    day:" 
    elif [[ $nextPref == "   day:" ]] 
    then 
     nextPref="    hour:" 
    elif [[ $nextPref == "   hour:" ]] 
    then 
     nextPref="    commits:" 
    elif [[ $nextPref == "   commits:" ]] 
    then 
     nextPref="  " 
    fi 
done