atlassian-json/json-backups/sourcetreeapp.csx

44 lines
1.4 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;
2024-12-02 21:29:34 +03:00
using System.Net.Http;
2021-01-17 02:29:47 +03:00
using System.Text.Json;
2024-12-02 21:29:34 +03:00
using System.Threading.Tasks;
2021-01-17 02:29:47 +03:00
2024-12-02 21:29:34 +03:00
const string userAgent = "YourCustomUserAgent/1.0";
var client = new HttpClient();
client.DefaultRequestHeaders.UserAgent.ParseAdd(userAgent);
var source = await client
2021-01-17 02:29:47 +03:00
.GetStringAsync("https://www.sourcetreeapp.com")
.ConfigureAwait(false);
var (startText, endText) = ("{ \"type\":\"imkt.components.SourcetreeDownload\"", "</scri");
2024-12-02 21:29:34 +03:00
var startIndex = source.IndexOf(startText, StringComparison.Ordinal);
var endIndex = source.IndexOf(endText, startIndex, StringComparison.Ordinal);
2021-01-17 02:29:47 +03:00
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(),
2024-12-02 21:29:34 +03:00
Version = new[] { "sourcetree", "enterprise", "setup" }
2021-01-17 02:29:47 +03:00
.Aggregate(Path.GetFileNameWithoutExtension(a.AbsolutePath), (s, ptr) => s.Replace(ptr, "", StringComparison.OrdinalIgnoreCase))
.TrimStart('-', '_')
})
2024-12-02 21:29:34 +03:00
.ToArray()) + ")");
2021-01-17 02:29:47 +03:00
public record Wrap(Params Params);
2021-01-17 05:04:03 +03:00
public record Params(string MacUrl, string WindowsUrl, string EnterpriseUrl);