GitHub 给了开发者相当丰富的 API 接口 https://developer.github.com/v3/,包括认证,搜索,活动等接口,但就是没有提供获取 Trending 的接口。因此,需要自己来实现这个api
获取热门项目
请求结果:
{"success": true,"count": 25,"msg": [
{
# 仓库名称"repo": "Librefox",
# 项目语言"language": "JavaScript",
# 项目拥有着"user": "intika",
# 项目简介"about": "Librefox: Firefox with privacy enhancements",
# 项目地址"link": "https://github.com/intika/Librefox",
# 项目star数"stars": "495",
# 项目fork数"forks": "14",
# 新增star数"new_stars": "117 stars today",
# 项目维护者头像地址"avatars": ["https://avatars2.githubusercontent.com/u/6892180?s=40&v=4","https://avatars0.githubusercontent.com/u/152493?s=40&v=4","https://avatars3.githubusercontent.com/u/2353785?s=40&v=4","https://avatars3.githubusercontent.com/u/38463143?s=40&v=4"]
},
...
获取热门开发者
{
success:true,
count:25,
msg: [
{
# 开发者用户名
username:"thunlp (THUNLP)",
# 开发者头像
avatar:"https://avatars1.githubusercontent.com/u/18389035?s=96&v=4",
# 开发者主页
userlink:"https://github.com/thunlp",
# 开发者热门项目
repo:"NRLPapers",
# 热门项目简介
repo_about:"Must-read papers on network representation learning (NRL) / network embedding (NE)"},
获取某种语言或开发者在某段时间内的trending
请求路径
请求参数:
lang 语言, 参数来自config.py中的 GithubLanguages
since 日期,参数有 daily,weekly, monthly
daily 每天 weekly 每周 monthly 每月
获取GitHub上的所有trending 语言。
返回结果:
{"success": true,"count": 490,"msg": ["Zimpl","Zephir","YASnippet","YARA","YANG","YAML","Yacc","Xtend","XSLT","XS",
...
请求出错
当请求的lang或since不存在时,请求出错。错误结果为:
{"success": false,"count": 0,"msg": "请求错误"}
安装项目代码
1. git clone https://github.com/ngauerh/GithubTrendingApi.git
2. pip install -r requirements.txt
3 . 修改config.py 文件
SinceDate: 不能更改
DB: 数据库配置
SERVER_PORT: 要运行的api服务的端口号
CRAWL_INTERVAL: 抓取间隔时间(实际间隔时间会曾经一个多小时)
4. 运行models.py 生成数据表(数据库格式需要为utf8mb4,如果格式为utf8则数据存入时会出错)
5. 运行run.py