-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
96 lines (77 loc) · 3.81 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System.Text;
using Imgur.API.Authentication;
using Imgur.API.Endpoints;
using PuppeteerSharp;
internal class Program
{
private static async Task Main(string[] args)
{
var matches = int.Parse(args.ElementAtOrDefault(1) ?? "4");
var drafts = int.Parse(args.ElementAtOrDefault(2) ?? "8");
var browserlessTOKEN = Environment.GetEnvironmentVariable("BROWSERLESS_TOKEN");
var imgurCLIENTKEY = Environment.GetEnvironmentVariable("IMGUR_CLIENT_KEY");
var browser = await Puppeteer.ConnectAsync(new ConnectOptions() { BrowserWSEndpoint = $"wss://chrome.browserless.io?token={browserlessTOKEN}" });
try
{
var apiClient = new ApiClient(imgurCLIENTKEY);
var httpClient = new HttpClient();
var imageEndpoint = new ImageEndpoint(apiClient, httpClient);
//await browser.DefaultContext.OverridePermissionsAsync("https://lotus.highgroundvision.com", new [] { OverridePermission.ClipboardReadWrite });
var page = await browser.NewPageAsync();
page.DefaultNavigationTimeout = 0;
await page.SetViewportAsync(new ViewPortOptions { Width = 1280, Height = 720 });
await page.GoToAsync($"https://lotus.highgroundvision.com/bd/?default=win-rate");
var markdown = new StringBuilder();
// Loop Through Matches and Drafts
for (int m = 1; m <= matches; m++)
{
markdown.AppendLine("# Match " + m);
markdown.AppendLine();
for (int d = 1; d <= drafts; d++)
{
markdown.AppendLine("## Draft " + d);
markdown.AppendLine();
var generateButton = await page.WaitForSelectorAsync("#generate");
await generateButton.ClickAsync();
// Wait for Images to load
await Task.Delay(TimeSpan.FromSeconds(3));
// Get commands
var preCommands = await page.QuerySelectorAsync("#commands");
var roasterCommands = await preCommands.EvaluateFunctionAsync<string>("_ => _.innerText");
await preCommands.DisposeAsync();
// Get Image
var roasterElement = await page.WaitForSelectorAsync("#roster");
var stream = await roasterElement.ScreenshotStreamAsync(new ScreenshotOptions() { Type = ScreenshotType.Png });
await roasterElement.DisposeAsync();
// TODO: Save Image in folder
using var fs = File.OpenWrite($"./output/Match {m} - Draft {d}.png");
await stream.CopyToAsync(fs);
stream.Seek(0, SeekOrigin.Begin);
// Upload Image
var imageUpload = await imageEndpoint.UploadImageAsync(stream);
// Create Markdown
markdown.AppendLine($"![Draft {d}]({imageUpload.Link})");
markdown.AppendLine();
markdown.AppendLine($"[{imageUpload.Link}]({imageUpload.Link})");
markdown.AppendLine();
markdown.AppendLine("```");
markdown.AppendLine(roasterCommands);
markdown.AppendLine("```");
markdown.AppendLine();
}
}
await page.DisposeAsync();
await File.WriteAllTextAsync("./output/lotus.md", markdown.ToString());
Console.WriteLine("Hello From Phylactery!");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
await browser.CloseAsync();
await browser.DisposeAsync();
}
}
}