atlassian-json/json-backups/sourcetreeapp.csx

37 lines
1.3 KiB
Plaintext
Raw Normal View History

2021-01-17 02:29:47 +03:00
#r "nuget: AngleSharp, 1.0.0-alpha-844"
using System;
using System.IO;
using System.Linq;
using System.Text.Json;
var source = await new System.Net.Http.HttpClient()
.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);
source = source[startIndex..endIndex];
var json = JsonSerializer.Deserialize<Wrap>(source, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
var (a, b, c) = json.Params;
var urls = new[] { a, b, c };
Console.Out.WriteLine(
2021-01-17 05:04:03 +03:00
"downloads(" +
2021-01-17 02:29:47 +03:00
JsonSerializer.Serialize(
urls
.Select(a => new Uri(a))
.Select(a => new
{
2021-01-19 18:49:04 +03:00
ZipUrl = a.ToString(),
2021-01-17 02:29:47 +03:00
Version = new[] { "sourcetree", "enterprise", "setup", }
.Aggregate(Path.GetFileNameWithoutExtension(a.AbsolutePath), (s, ptr) => s.Replace(ptr, "", StringComparison.OrdinalIgnoreCase))
.TrimStart('-', '_')
})
.ToArray())+ ")");
public record Wrap(Params Params);
2021-01-17 05:04:03 +03:00
public record Params(string MacUrl, string WindowsUrl, string EnterpriseUrl);