mirror of
https://github.com/EpicMorg/atlassian-json.git
synced 2025-03-03 17:15:20 +03:00
fix json generator for sourcetree
This commit is contained in:
parent
5478bd3cbe
commit
cf68a3a9c8
@ -1,15 +1,22 @@
|
||||
#r "nuget: AngleSharp, 1.0.0-alpha-844"
|
||||
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using AngleSharp.Html.Parser;
|
||||
|
||||
string userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:101.0) Gecko/20100101 Firefox/101.0";
|
||||
|
||||
var client = new HttpClient();
|
||||
client.DefaultRequestHeaders.UserAgent.ParseAdd(userAgent);
|
||||
|
||||
System.Console.Out.WriteLine(
|
||||
"downloads(" + System.Text.Json.JsonSerializer.Serialize(
|
||||
new AngleSharp.Html.Parser.HtmlParser()
|
||||
new HtmlParser()
|
||||
.ParseDocument(
|
||||
await new System.Net.Http.HttpClient()
|
||||
await client
|
||||
.GetStringAsync("https://www.sourcetreeapp.com/download-archives")
|
||||
.ConfigureAwait(false))
|
||||
.QuerySelectorAll(".wpl tr div>a")
|
||||
.Select(row => new { Version = row.TextContent, ZipUrl = row.GetAttribute("href") })
|
||||
.Select(row => new { Version = row.TextContent.Trim(), ZipUrl = row.GetAttribute("href") })
|
||||
.ToArray()) + ")"
|
||||
);
|
||||
|
@ -3,15 +3,22 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
var source = await new System.Net.Http.HttpClient()
|
||||
const string userAgent = "YourCustomUserAgent/1.0";
|
||||
|
||||
var client = new HttpClient();
|
||||
client.DefaultRequestHeaders.UserAgent.ParseAdd(userAgent);
|
||||
|
||||
var source = await client
|
||||
.GetStringAsync("https://www.sourcetreeapp.com")
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var (startText, endText) = ("{ \"type\":\"imkt.components.SourcetreeDownload\"", "</scri");
|
||||
var startIndex = source.IndexOf(startText, System.StringComparison.Ordinal);
|
||||
var endIndex = source.IndexOf(endText, startIndex, System.StringComparison.Ordinal);
|
||||
var startIndex = source.IndexOf(startText, StringComparison.Ordinal);
|
||||
var endIndex = source.IndexOf(endText, startIndex, StringComparison.Ordinal);
|
||||
source = source[startIndex..endIndex];
|
||||
|
||||
var json = JsonSerializer.Deserialize<Wrap>(source, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
@ -26,11 +33,11 @@ Console.Out.WriteLine(
|
||||
.Select(a => new
|
||||
{
|
||||
ZipUrl = a.ToString(),
|
||||
Version = new[] { "sourcetree", "enterprise", "setup", }
|
||||
Version = new[] { "sourcetree", "enterprise", "setup" }
|
||||
.Aggregate(Path.GetFileNameWithoutExtension(a.AbsolutePath), (s, ptr) => s.Replace(ptr, "", StringComparison.OrdinalIgnoreCase))
|
||||
.TrimStart('-', '_')
|
||||
})
|
||||
.ToArray())+ ")");
|
||||
.ToArray()) + ")");
|
||||
|
||||
public record Wrap(Params Params);
|
||||
public record Params(string MacUrl, string WindowsUrl, string EnterpriseUrl);
|
||||
|
Loading…
x
Reference in New Issue
Block a user