Last active
October 18, 2024 03:35
-
-
Save nuitsjp/d29be1a65ddf9e2281cee7bdf5100b4c to your computer and use it in GitHub Desktop.
Count download of GitHub release module.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json.Linq; | |
using System; | |
using System.Net.Http; | |
using System.Linq; | |
using System.Threading.Tasks; | |
public static class GitHubCounter | |
{ | |
public static async Task CountDownload(string owner, string repository) | |
{ | |
using (var httpClient = new HttpClient()) | |
{ | |
httpClient.DefaultRequestHeaders.Add("User-Agent", "C# HttpClient"); | |
var downloadCount = | |
JArray | |
.Parse(await httpClient.GetStringAsync($"https://api.github.com/repos/{owner}/{repository}/releases")) | |
.SelectMany(x => JArray.FromObject(x["assets"])) | |
.Sum(x => int.Parse((string)x["download_count"])); | |
Console.WriteLine(downloadCount); | |
} | |
} | |
} | |
更新日時: 2024-10-18 11:34:28 | |
更新日時: 2024-10-18 12:29:41 | |
更新日時: 2024-10-18 12:35:30 | |
更新日時: 2024-10-18 12:35:33 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment