1 Star 14 Fork 0

晨旭 / 森川Sakura和其他9位小伙伴给了这个项目星星哦

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Program.cs 2.27 KB
一键复制 编辑 原始数据 按行查看 历史
晨旭 提交于 2021-02-19 22:45 . 加上token,防止403
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RestSharp;
using RestSharp.Authenticators;
using System;
using System.Threading;
namespace github_control
{
class Program
{
private static RestClient Client;
private static int LastCount = 0;
private static string LastUser = "";
private static string access_token = "";
private static (int,string) Check()
{
var request = new RestRequest("", DataFormat.Json);
request.AddObject(new
{
access_token,
});
var response = Client.Get(request);
var stars = (int)JsonConvert.DeserializeObject<JObject>(response.Content)["stargazers_count"];
request = new RestRequest("stargazers", DataFormat.Json);
request.AddObject(new
{
access_token,
page = stars,
per_page = 1
});
response = Client.Get(request);
var user = (string)JsonConvert.DeserializeObject<JArray>(response.Content)[0]["name"];
return (stars,user);
}
private static void SetName(string name)
{
var request = new RestRequest("", DataFormat.Json);
request.AddObject(new
{
access_token,
name
});
var r = Client.Patch(request);
Console.WriteLine(r.Content);
}
static void Main(string[] args)
{
Client = new RestClient("https://gitee.com/api/v5/repos/chenxuuu/instresting-repo");
while (true)
{
try
{
var (s, u) = Check();
if (s != LastCount || u != LastUser)
{
LastCount = s;
LastUser = u;
SetName($"{u}和其他{s - 1}位小伙伴给了这个项目星星哦");
Console.WriteLine($"name changed:{u}和其他{s - 1}位小伙伴给了这个项目星星哦");
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Thread.Sleep(10000);
}
}
}
}
C#
1
https://gitee.com/chenxuuu/instresting-repo.git
git@gitee.com:chenxuuu/instresting-repo.git
chenxuuu
instresting-repo
森川Sakura和其他9位小伙伴给了这个项目星星哦
master

搜索帮助