Skip to content

Instantly share code, notes, and snippets.

@Grabacr07

Grabacr07/Counter.cs

Last active Aug 28, 2018
Embed
What would you like to do?
LINQPad で KanColleViewer のダウンロード数かぞえるやつ (要 Json.NET)
using (var client = new HttpClient())
{
var url = new Uri("https://api.github.com/repos/Grabacr07/KanColleViewer/releases");
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Grabacr07-LINQPad", "1.0"));
var result = Util.Cache(() => client.GetAsync(url).Result);
var json = await result.Content.ReadAsStringAsync();
var start = new DateTime(2015, 02, 01);
var end = start.AddYears(1).AddMilliseconds(-1.0);
var assets = JArray.Parse(json)
.SelectMany(x => JArray.FromObject(x["assets"]))
.Select(x => new
{
Date = DateTime.Parse(x["created_at"].ToString()),
Name = x["name"],
Count = (int)x["download_count"],
})
.Where(x => start <= x.Date && x.Date <= end)
.ToArray();
assets.Dump();
$"DL: {assets.Sum(x => x.Count):#,##0}".Dump($"{start:yyyy/MM} - {end:yyyy/MM}");
}
// GET /repos/:owner/:repo/releases
// …が複数ページ形式で返してくるので、☝はおそらく途中までしか取得できてない (1 年分には足りる)
// ので、全件取得するときは複数ページ分取得する実装を入れないとダメぽよ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.