如何通过github api获取趋势github存储库列表?

时间:2015-05-29 08:56:33

标签: github-api

我希望得到这样的github趋势回购列表 - https://github.com/trending?l=java 但我没有在https://developer.github.com/v3/找到任何类似的请求方法,我如何通过趋势回购获得json响应?

4 个答案:

答案 0 :(得分:25)

GitHub似乎使用他们的API来编写趋势页面,而不是将其作为特定API呈现。您需要使用Repository Search API。我已经关注了examples on this page,它可以通过以下方式解决您的需求:

# We'll use the `date` command to get the date for "7 days ago"
$ date -v-7d '+%Y-%m-%d'
# => 2013-07-15

curl -G https://api.github.com/search/repositories --data-urlencode "sort=stars" --data-urlencode "order=desc" --data-urlencode "q=language:java"  --data-urlencode "q=created:>`date -v-7d '+%Y-%m-%d'`"

然后从那里开始。您还可以通过在OS X或其他平台上安装jq来让您的生活更轻松,以获得更漂亮的输出:

curl -G https://api.github.com/search/repositories --data-urlencode "sort=stars" --data-urlencode "order=desc" --data-urlencode "q=language:java"  --data-urlencode "q=created:>`date -v-7d '+%Y-%m-%d'`" | jq ".items[0,1,2] | {name, description, language, watchers_count, html_url}"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- -- 77  161k   77  125k    0     0   131k      0  0:00:01 --:--:--  0100  161k  100  161k    0     0   163k      0 --:--:-- --:--:-- --:--:--  163k
{
  "name": "vibrant.js",
  "description": "Extract prominent colors from an image. JS port of Android's Palette.",
  "language": "JavaScript",
  "watchers_count": 1466,
  "html_url": "https://github.com/jariz/vibrant.js"
}
{
  "name": "JSPatch",
  "description": "JSPatch bridge Objective-C and JavaScript using the Objective-C runtime. You can call any Objective-C class and method in JavaScript by just including a small engine.",
  "language": "Objective-C",
  "watchers_count": 830,
  "html_url": "https://github.com/bang590/JSPatch"
}
{
  "name": "KRVideoPlayer",
  "description": "类似Weico的播放器,支持竖屏模式下全屏播放",
  "language": "Objective-C",
  "watchers_count": 524,
  "html_url": "https://github.com/36Kr-Mobile/KRVideoPlayer"
}

答案 1 :(得分:3)

目前没有GitHub API来获取趋势存储库列表。唯一的方法是通过选择器从网页抓取项目。您可以在Chrome中打开https://github.com/trending并在devtools控制台中运行以下代码:

select *, cast(null as Decimal(18,2)) as buyavg into #temp from dbo.YourTable where 1=2
;



DECLARE @id int
DECLARE @previd int
DECLARE @prvBuyAvg decimal(18,2)
DECLARE @prvKcode int
DECLARE db_cursor CURSOR FOR  

SELECT Id, LAG(Id) OVER (ORDER BY Kcode,datee,id) prevId
FROM dbo.YourTable
order by Kcode,datee,id

OPEN db_cursor   
FETCH NEXT FROM db_cursor INTO @id, @previd   
WHILE @@FETCH_STATUS = 0   
BEGIN   
       select @prvKcode = Kcode, @prvBuyAvg = buyAvg
       from #temp where id = @previd

       insert into #temp  ([Id], [date], [Kcode] , [InOrder] , [pIn] , [SumIn] , OutOrder , pOut , SumOut , stock , LastStock , buyavg) 
       select [Id], [date], [Kcode] , [InOrder] , [pIn] , [SumIn] , OutOrder , pOut , SumOut , stock , LastStock ,

       case 
       when lastStock = 0 then 
            pIn 
       else 
            case 
            when InOrder = 0 then 
                 case 
                 when @prvKcode = Kcode then 
                      @prvBuyAvg 
                 else 
                       0 
                 end
            else 
                 case 
                 when @prvKcode = Kcode then 
                      ((sumIn) + (LastStock*@prvBuyAvg)) / (inOrder+LastStock)
                 else 
                      pIn 
                 end
            end
       end as newbuyAvg
       from dbo.YourTable  where id = @id

       FETCH NEXT FROM db_cursor INTO @id, @previd
END   
CLOSE db_cursor   
DEALLOCATE db_cursor
;

select * from #temp
;

这将输出趋势存储库名称列表。为了使其更加自动化,请考虑使用Headles Chrome或其他类似工具。

此外,有几个项目已经用不同的语言解决了这个问题。例如:

答案 2 :(得分:0)

似乎GitHub没有向公众提供正式的API来实现这种用例。 但是,您可以使用可以轻松满足您要求的项目之一。您可以在GitHub上尝试github-trending-api项目并实现该目标。

{ "item_name": "lettuce", "price": 2.65, "units": "no" }
{ "item_name": "ketchup", "price": 1.51, "units": "litres" }

这将为您在GitHub上获取当今的热门项目。 祝你好运。

答案 3 :(得分:0)

我正在尝试为上述用例制作一个android应用程序,发现this api非常完整,可以将languagesince用作可选参数来获取特定于语言的回购并显示数字或日期的趋势。

  

https://github-trending-api.now.sh/repositories?since=daily

Reference