Skip to content

Instantly share code, notes, and snippets.

@nuitsjp
Last active October 18, 2024 03:35
Show Gist options
  • Save nuitsjp/d29be1a65ddf9e2281cee7bdf5100b4c to your computer and use it in GitHub Desktop.
Save nuitsjp/d29be1a65ddf9e2281cee7bdf5100b4c to your computer and use it in GitHub Desktop.
Count download of GitHub release module.
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