Otto ricette (controllo del profilo, storico, taggati, reel, storie di un account, raccolta in evidenza, post singolo, elenco dei seguiti) hanno una strada per richieste dirette accanto a quella con il browser. Ci vanno solo se ogni ruolo che servono è un'operazione configurata di richieste.<sito>.json: con Instagram nessuna lo è e Febe non costruisce il client del sito, quindi il comportamento con Instagram non cambia fino a S4. Ogni richiesta prende il suo permesso dal Governatore nella categoria di ciò che chiede (la prima pagina dei post conta come profilo); i segnali delle risposte vanno all'interruttore e fermano la ricetta prima di ogni altra richiesta. Se manca un valore o la pagina successiva, la ricetta torna alle pagine per quella volta e il motore controlla tutti e due i tetti. I tetti non cambiano: il dimezzamento delle storie viste è tolto perché toccava anche il browser e i «Su misura» salvati, e resta una domanda per Alberto prima di S4. Il simulatore ha --raccolta pagine|richieste con il costo delle operazioni separate di Instagram: sei simulazioni di 30 giorni senza superamenti. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
114 lines
4.8 KiB
C#
114 lines
4.8 KiB
C#
using System.Globalization;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Nodes;
|
|
using Febe.SitoDiProva;
|
|
|
|
// Local test site (spec §14.2).
|
|
// febe-sito-di-prova [--porta 8481] [--porta-cdn 8482] [--indirizzo-cdn 127.0.0.2] [--seme 13]
|
|
// febe-sito-di-prova campioni --cartella <cartella fuori dal repository> [--seme 13]
|
|
if (args.Length > 0 && args[0] == "campioni")
|
|
{
|
|
return await DumpSamplesAsync(args[1..]);
|
|
}
|
|
|
|
var options = new TestSiteOptions
|
|
{
|
|
Port = IntOption(args, "--porta", 8481),
|
|
CdnPort = IntOption(args, "--porta-cdn", 8482),
|
|
CdnAddress = Option(args, "--indirizzo-cdn") ?? "127.0.0.2",
|
|
Seed = IntOption(args, "--seme", 13),
|
|
ConsoleLog = true,
|
|
};
|
|
await using var site = await TestSite.StartAsync(options);
|
|
Console.WriteLine($"Sito di prova: {site.SiteUrl}/ · CDN: {site.CdnUrl}/ · seme {options.Seed.ToString(CultureInfo.InvariantCulture)}");
|
|
Console.WriteLine($"Casi di arresto: {site.SiteUrl}/_controllo/modo?valore=troppe-richieste|verifica|sessione-scaduta|vuoto|normale");
|
|
Console.WriteLine("Ctrl+C per fermare.");
|
|
var stop = new TaskCompletionSource();
|
|
Console.CancelKeyPress += (_, e) =>
|
|
{
|
|
e.Cancel = true;
|
|
stop.TrySetResult();
|
|
};
|
|
await stop.Task;
|
|
return 0;
|
|
|
|
// Writes the JSON responses of the main pages in the raw format of the probe (descriptor + body), to be cleaned with
|
|
// «febe-sonda ripulisci». The data is synthetic, but the samples follow the same path as real ones (spec §14.5).
|
|
static async Task<int> DumpSamplesAsync(string[] args)
|
|
{
|
|
var folder = Option(args, "--cartella");
|
|
if (string.IsNullOrWhiteSpace(folder))
|
|
{
|
|
Console.Error.WriteLine("Indicare --cartella <cartella fuori dal repository>.");
|
|
return 2;
|
|
}
|
|
|
|
Directory.CreateDirectory(folder);
|
|
await using var site = await TestSite.StartAsync(new TestSiteOptions { Seed = IntOption(args, "--seme", 13) });
|
|
string marta, luca, code;
|
|
lock (site.World.Gate)
|
|
{
|
|
marta = site.World.FindByUsername("marta.prova")!.Username;
|
|
luca = site.World.FindByUsername("luca.prova")!.Username;
|
|
code = site.World.FindByUsername("marta.prova")!.Posts.First(p => p.Files.Count > 1).Code;
|
|
}
|
|
|
|
var samples = new (string Name, string Path)[]
|
|
{
|
|
("inizio", "/dati/inizio"),
|
|
("profilo-pubblico", $"/dati/profilo/{marta}?scheda=post"),
|
|
("profilo-pagina-successiva", $"/dati/profilo/{luca}/altri?scheda=post&dopo=c12"),
|
|
("profilo-privato-non-seguito", "/dati/profilo/riservato.prova?scheda=post"),
|
|
("post-serie", $"/dati/post/{code}"),
|
|
("storie", $"/dati/storie/{marta}"),
|
|
("raccolta", $"/dati/evidenza/{site.World.FindByUsername("marta.prova")!.Highlights[0].Id}"),
|
|
("seguiti", "/dati/seguiti"),
|
|
("taggati", $"/dati/profilo/{marta}?scheda=taggati"),
|
|
};
|
|
|
|
var number = 0;
|
|
foreach (var (name, path) in samples)
|
|
{
|
|
var body = JsonNode.Parse(await site.GetDataAsync(path));
|
|
await WriteSampleAsync(folder, ++number, name, site.Url(path), 200, body);
|
|
}
|
|
|
|
site.Control.Set(StopMode.EmptyPages);
|
|
await WriteSampleAsync(folder, ++number, "pagina-vuota", site.Url($"/dati/profilo/{luca}/altri?scheda=post&dopo=c48"), 200, JsonNode.Parse(await site.GetDataAsync($"/dati/profilo/{luca}/altri?scheda=post&dopo=c48")));
|
|
site.Control.Set(StopMode.Normal);
|
|
|
|
// 000011 is «forma-sconosciuta», written by hand. The reels of every account fit in one page (12): no next page.
|
|
number++;
|
|
await WriteSampleAsync(folder, ++number, "reel", site.Url($"/dati/profilo/{luca}?scheda=reel"), 200, JsonNode.Parse(await site.GetDataAsync($"/dati/profilo/{luca}?scheda=reel")));
|
|
Console.WriteLine($"Scritti {(number - 1).ToString(CultureInfo.InvariantCulture)} campioni grezzi in {folder} (il numero 11 si scrive a mano).");
|
|
return 0;
|
|
}
|
|
|
|
static async Task WriteSampleAsync(string folder, int number, string name, string url, int status, JsonNode? body)
|
|
{
|
|
var sample = new JsonObject
|
|
{
|
|
["descrittore"] = new JsonObject
|
|
{
|
|
["indirizzo"] = url.Split('?')[0],
|
|
["host"] = "sito",
|
|
["stato"] = status,
|
|
["tipo"] = "application/json",
|
|
["risorsa"] = "Fetch",
|
|
["nome"] = name,
|
|
},
|
|
["corpo"] = body,
|
|
};
|
|
var file = Path.Combine(folder, $"{number.ToString("000000", CultureInfo.InvariantCulture)}-{name}.json");
|
|
await File.WriteAllTextAsync(file, sample.ToJsonString(new JsonSerializerOptions { WriteIndented = true }));
|
|
}
|
|
|
|
static string? Option(string[] args, string name)
|
|
{
|
|
var index = Array.IndexOf(args, name);
|
|
return index >= 0 && index + 1 < args.Length ? args[index + 1] : null;
|
|
}
|
|
|
|
static int IntOption(string[] args, string name, int fallback) =>
|
|
int.TryParse(Option(args, name), NumberStyles.Integer, CultureInfo.InvariantCulture, out var value) ? value : fallback;
|