This repository has been archived by the owner on Jul 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
62 lines (56 loc) · 2.2 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text;
using System.Threading.Tasks;
namespace WFBotSponsorUpdater
{
class Program
{
static async Task Main(string[] args)
{
var sponsors = await GetAllSponsors();
var sponsorsText = string.Join(' ', sponsors.Select(s => s.Name));
const string Magic = "<!--SPONSORS_BEGIN-->";
var sponsorsLine = Magic + sponsorsText;
var lines = await File.ReadAllLinesAsync("README.md", new UTF8Encoding(false));
for (var i = 0; i < lines.Length; i++)
{
var lineInReadme = lines[i];
if (lineInReadme.StartsWith(Magic))
{
if (lineInReadme != sponsorsLine)
{
lines[i] = sponsorsLine;
}
break;
}
}
File.WriteAllLines("README.md", lines, new UTF8Encoding(false));
}
static async Task<List<User>> GetAllSponsors()
{
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36 Edg/91.0.864.54");
httpClient.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
int page = 1;
ApiResult result;
var list = new List<User>();
do
{
result = await httpClient.GetFromJsonAsync<ApiResult>($"https://afdian.net/api/creator/get-sponsors?user_id=6278895e1f1511e9836c52540025c377&type=new&page={page}");
if (result!.Ec != 200)
{
Console.WriteLine(result);
Environment.Exit(-1);
}
list.AddRange(result.Data.User);
page++;
} while (result.Data.User.Length != 0);
return list;
}
}
}