GitHub API - Different number of results for jq filtered response

跟風遠走 提交于 2019-12-11 20:39:50

问题


I am trying to use the GitHub API to make a list of well documented, open source Java libraries. To do so, I went through the GitHub API documentation and made this simple curl.

curl -G  https://api.github.com/search/repositories?q=language:Java+stars:%3E=500+library+java+in:readme > output1.txt

The output of this is a giant txt file, containing information about all of the repositories found. In this example, there was a total of 736 matches. However, the file from the command above is quite unreadable, so I decided to do some parsing using jq, which resulted in the following code:

curl -G  https://api.github.com/search/repositories?q=language:Java+stars:%3E=500+library+java+in:readme \
 | jq ".items[] | {name, description, language, watchers_count, html_url}" > parsedOutput1.txt

After this, instead of 736 results, I got something around 30 repositories, which is unacceptable for my purposes.

Doing this search: language:java stars:>=500 java library in:readme in the GitHub search box gives me the same 736 results. I don't really know what i am doing wrong so I could use the help.


回答1:


It was a paging problem, as presented in the documentation, the api only gives you 30 items per request, so you need to add some code to include all the pages. I was using bash so my code ended up like this:

 for i in `seq 1 34`;
        do
            URL="https://api.github.com/search/repositories?q=language:Java+stars:%3E=500+library+java+in:readme&page=$i"
            echo $URL
            curl -G  $URL \
            | jq ".items[] | {name, description, language, watchers_count, html_url}" >> parsedOutput1.txt
        done

On another note, when doing a lot of requests you should authenticate, otherwise you will end up with the API rate limit exceeded message.



来源:https://stackoverflow.com/questions/52228774/github-api-different-number-of-results-for-jq-filtered-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!