{"id":13699628,"url":"https://github.com/ButterAndButterfly/GithubTools","last_synced_at":"2025-05-04T16:35:29.780Z","repository":{"id":41496001,"uuid":"336440347","full_name":"ButterAndButterfly/GithubTools","owner":"ButterAndButterfly","description":"目标是创建会刷新的ReadMe首页！    在这里，你可以得到Github star/fork总数图标, 项目star历史曲线，star数最多的前N个Repo信息...","archived":false,"fork":false,"pushed_at":"2024-10-30T01:17:16.000Z","size":35938,"stargazers_count":10,"open_issues_count":0,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-30T03:55:15.178Z","etag":null,"topics":["github-api","graphql"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ButterAndButterfly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-06T02:44:41.000Z","updated_at":"2024-10-30T01:17:19.000Z","dependencies_parsed_at":"2023-09-24T03:33:18.037Z","dependency_job_id":"ce5d6626-2ce9-4853-b3aa-abcf5a0fa7ed","html_url":"https://github.com/ButterAndButterfly/GithubTools","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ButterAndButterfly%2FGithubTools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ButterAndButterfly%2FGithubTools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ButterAndButterfly%2FGithubTools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ButterAndButterfly%2FGithubTools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ButterAndButterfly","download_url":"https://codeload.github.com/ButterAndButterfly/GithubTools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224398825,"owners_count":17304661,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["github-api","graphql"],"created_at":"2024-08-02T20:00:38.585Z","updated_at":"2024-11-13T05:31:55.654Z","avatar_url":"https://github.com/ButterAndButterfly.png","language":"Python","readme":"\u003cp align=\"center\"\u003e\n      \u003cstrong\u003e\n        \u003ca href=\"https://github.com/ButterAndButterfly/GithubTools\" target=\"_blank\"\u003eGithub 工具箱\u003c/a\u003e\u0026nbsp;\n      \u003c/strong\u003e\n  \u003cbr\u003e\n      源自\u003cstrong\u003e\n        \u003ca href=\"https://github.com/ButterAndButterfly\" target=\"_blank\"\u003eButterAndButterfly\u003c/a\u003e\u003cbr\u003e\n      \u003c/strong\u003e  \n        Butter, 寓意宅男; Butterfly, 寓意美好的事物。 \n        \u003cbr/\u003e 美好的世界由我们创造!  \n\u003c/p\u003e\n\n## 功能  \n+ 统计个人/组织的star总数和fork总数(基于Github graphQL)\n+ 统计个人/组织的star数最多的项目信息(基于Github graphQL)\n+ 统计项目的star历史数据并绘图(基于Github API v3)\n+ 【**开箱即用**】提供完整的静态的图片生成方法，只需要fork后简单修改配置即可转为自己使用(基于Github Actions)\n+ 【**开箱即用**】提供现成的动态的图片。(因为Github API的访问频率限制，有可能获取失败。您也可以clone/fork后自己部署在vercel上。)\n+ 【**开箱即用**】提供会自动刷新的ReadMe首页。[Demo](https://github.com/ButterAndButterfly/GithubTools/tree/master/data)\n\n## 展示\n### 动态star/fork总数\n![](https://img.shields.io/badge/dynamic/json?label=Total%20Stars\u0026cacheSeconds=3600\u0026query=stars\u0026url=https://github.nicelee.vercel.app/s/nICEnnnnnnnLee)  \n### 静态star/fork总数(刷新周期为1天)\n![](https://img.shields.io/badge/dynamic/json?label=Total%20Stars\u0026cacheSeconds=3600\u0026query=stars\u0026url=https://raw.githubusercontent.com/ButterAndButterfly/GithubTools/master/data/total.json)  \n\n### 动态star历史数\n![](https://github.nicelee.vercel.app/h/nICEnnnnnnnLee/bilibilidown?div=4)  \n\n### 静态star历史数(刷新周期为1天)\n![](https://raw.githubusercontent.com/ButterAndButterfly/GithubTools/master/data/stars_history.jpg) \n\n## 使用  \n\u003cdetails\u003e\n\u003csummary\u003e最快捷的方法\u003c/summary\u003e\n\n\n+ 某人或组织的star/fork 总数: \n    + json信息：\n        + 链接：`https://github.nicelee.vercel.app/s/{user}` \n        + 举例：\u003chttps://github.nicelee.vercel.app/s/nICEnnnnnnnLee\u003e  \n    + 有了这个，我们可以根据`shields.io`的接口提供图片：\n        + 链接：`https://img.shields.io/badge/dynamic/json?label=Total%20Stars\u0026cacheSeconds=3600\u0026query=stars\u0026url={查询接口}`\n        + 举例：\u003chttps://img.shields.io/badge/dynamic/json?label=Total%20Stars\u0026cacheSeconds=3600\u0026query=stars\u0026url=https://github.nicelee.vercel.app/s/nICEnnnnnnnLee\u003e \n+ 某项目的star历史图：\n    + 链接：`https://github.nicelee.vercel.app/h/{owner}/{repo}`\n    + 举例：\u003chttps://github.nicelee.vercel.app/h/nICEnnnnnnnLee/bilibilidown?div=4\u003e  \n    + 可以通过适当增大`div`参数来增加取样点  \n\n+ 因为**Github API的访问频率限制**，有可能获取失败。\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\n\u003csummary\u003e最实用的方法 - Github静态部署\u003c/summary\u003e\n\n\n+ 原理： 使用Github Actions周期(默认每天)查询并保存生成的相关数据，访问静态数据即可。  \n+ 步骤：\n    1. fork本项目，并**激活Actions**\n    2. 修改`config.json`\n    ```\n    {\n        \"token\":\"token\", //因为安全需要，最好在项目里面设置，此处可不填\n        \"tasks\":[ // tasks 是一个任务数组，可根据需要删除或增加任务\n            {\n                \"type\": \"get_total_stars_and_forks\", //获取某用户/组织的stars和forks总数\n                \"name\":\"nICEnnnnnnnLee\",             // 可以是user 或者 organization 或者任意相加，比如nICEnnnnnnnLee+ButterAndButterfly\n                \"output\":\"data/total.json\"           // 保存的路径\n            },{\n                \"type\": \"get_stars_history\",         //获取某项目的star历史图\n                \"name\":\"nICEnnnnnnnLee\",             // 可以是user 或者 organization\n                \"repo\":\"BilibiliDown\",               // repo的名字\n                \"div\":7,                             // 可以增大`div`参数来增加取样点\n                \"output\":\"data/stars_history.jpg\"    // 保存的路径\n            },{\n                \"type\": \"get_top_star_repos\",\n                \"name\":\"ButterAndButterfly\",         // 可以是user 或者 organization\n                \"top\":3,                             // 获取star数最多的TOP个\n                \"output\":\"data/top/ButterAndButterfly/top4.json\"\n            },{\n                \"type\": \"get_top_star_repos\",\n                \"name\":\"nICEnnnnnnnLee\",\n                \"top\":4,\n                \"output\":\"data/top/nICEnnnnnnnLee/top4.json\"\n            },{\n                \"type\": \"render_template\",  // 根据前面任务获取的数据来渲染模板，请确认模板里面的变量在前文已经生成，否则会报错\n                \"template_path\":\"README_template.md\",\n                \"output\":\"README.md\"  // 可以fork后将配置改为README.md，并将项目名改为你的用户名\n            }\n        ]\n    }\n    ```\n    4. 图片和数据会周期性地刷新，接下来是怎样访问的问题了。  \n        + Github raw：  \n        ```\n        https://raw.githubusercontent.com/{owner}/{repo}/master/{path}\n        举例： https://raw.githubusercontent.com/ButterAndButterfly/GithubTools/master/data/total.json\n        然后由img.shields.io生成图片，样式什么的可以自定义\n        ```\n        + jsdelivr CDN：\n        ```\n        https://cdn.jsdelivr.net/gh/{owner}/{repo}@master/{path}\n        举例： https://cdn.jsdelivr.net/gh/ButterAndButterfly/Q-Gif-ImgBed@master/2020/8/1/nICEnnnnnnnLee-1596288015648.gif\n        ```\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\n\u003csummary\u003e好吧，部署到vercel的方法\u003c/summary\u003e\n\n\n+ 简介： 提供现成的Serverless实现和配置\n+ 步骤：\n    1. [可选0-1]fork本项目，vercel上直接根据现有的项目新建\n    1. [可选0-2]克隆项目到本地，命令行cd 到目录后直接`vercel`(需要本地存在vercel环境)\n    2. 生成自己的`token`，权限不必给多（[参考](https://docs.github.com/en/graphql/guides/forming-calls-with-graphql#authenticating-with-graphql)）。点击[传送门](https://github.com/settings/tokens)  \n    3. 在vercel网页端的项目管理里面，设置环境变量   \n        + 链接:`https://vercel.com/{vercel用户名}/{vercel项目名}/settings/environment-variables`\n        + `name`为`MY_GITHUB_TOKEN`\n        + `value`为刚刚生成的token\n    4. 相关接口：\n    ```\n    json信息：{domain}/s/{user}\n    某项目的star历史图：{domain}/h/{owner}/{repo}`\n    ```        \n \n\u003c/details\u003e\n\n\n\u003cdetails\u003e\n\u003csummary\u003e给开发者\u003c/summary\u003e\n\n\n+ 有关数据查询的内容主要在`core/github.py`里面\n+ Star历史折线图绘制在`core/github_star_history.py`里面\n```\n伪代码\nfrom core import github, github_star_history\n\ntotal_dic = github.query_total(user, token)\ntotal_dic: {\"stars\":123,\"forks\":456}\n\ntop_repos_list = github.query_top(user, token, 3)\ntop_repos_list: [{\n\t\"name\": \"BilibiliDown\",\n\t\"stargazerCount\": 334,\n\t\"forkCount\": 51,\n\t\"description\": \"xxx\"\n}, {\n\t\"name\": \"BilibiliLiveRecorder\",\n\t\"stargazerCount\": 184,\n\t\"forkCount\": 34,\n\t\"description\": \"xxx\"\n}, {\n\t\"name\": \"LiveRecorder\",\n\t\"stargazerCount\": 56,\n\t\"forkCount\": 8,\n\t\"description\": \"xxx\"\n}]\n\nhistory_dic = github.query_star_history(user, repo, token, div = 7)\nhistory_dic: {\"2020-01-01\":1, \"2020-01-02\":4, \"2020-01-03\":6, \"2020-01-04\":9 }\n# key - 日期, value - 当天的star数量\n\njpg_bytes = github_star_history.draw(history_dic)\njpg_bytes: jpg图片的字节数组\n```\n\u003c/details\u003e\n\n## LICENSE\nMIT \n\n\n","funding_links":[],"categories":["4.4 Polynomials"],"sub_categories":["\u003cspan id=\"head72\"\u003e4.3.2. Interpolations and Approximations\u003c/span\u003e"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FButterAndButterfly%2FGithubTools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FButterAndButterfly%2FGithubTools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FButterAndButterfly%2FGithubTools/lists"}