xabbo-scripts/Scripts/CatalogScraper.csx
Administrator 7a548130a3 Move all scripts into Scripts/ subfolder
Keeps the repo root clean - only README.md visible on landing page.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 09:49:37 +01:00

59 lines
1.7 KiB
C#

/// @name Catalog Scraper
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.Encodings.Web;
var catalog = GetCatalog();
var nodes = catalog.Where(x => x.Id > 0).ToArray();
var pages = new List<(ICatalogPageNode Node, ICatalogPage Page)>();
for (int i = 0; i < nodes.Length; i++) {
var node = nodes[i];
Status($"Loading page {i+1}/{nodes.Length}...");
pages.Add((node, GetCatalogPage(node)));
await Task.Delay(300);
}
var opts = new JsonSerializerOptions {
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
WriteIndented = true
};
static bool IsFurni(IItem it) => it.Type == ItemType.Floor || it.Type == ItemType.Wall;
string json = JsonSerializer.Serialize(
pages.Select(x => new {
PageId = x.Node.Id,
x.Node.Name,
x.Node.Title,
x.Node.Icon,
x.Node.IsVisible,
x.Page.LayoutCode,
x.Page.Images,
x.Page.Texts,
x.Page.AcceptSeasonCurrencyAsCredits,
Offers = x.Page.Offers.Select(offer => new {
offer.Id,
offer.FurniLine,
offer.PriceInCredits,
offer.PriceInActivityPoints,
ActivityPointType = offer.ActivityPointType.ToString(),
offer.CanPurchaseAsGift,
offer.CanPurchaseMultiple,
offer.ClubLevel,
Products = offer.Products.Select(product => new {
Identifier = IsFurni(product) ? product.GetIdentifier() : null,
Name = IsFurni(product) ? product.GetIdentifier() : null,
Type = product.Type.ToString(),
product.Variant,
product.Count,
product.IsLimited
})
})
}),
opts
);
Directory.CreateDirectory("catalog");
File.WriteAllText($"catalog/{DateTime.Now:yyyyMMddHHmmssfff}.json", json);