Ricette fatte di richieste, un permesso per richiesta (#36, S3)
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>
This commit is contained in:
1 parent
4dcbd0b096
commit
63acae4e73
46 files changed
+3724
-136
No files matched your search
@@ -95,6 +95,9 @@ public sealed partial class RecipeRunner
|
||||
|
||||
/// <summary>No page came after the bursts (counted as an empty page).</summary>
|
||||
NoData,
|
||||
|
||||
/// <summary>By requests: the pages go on, but there is no request for the next one (no cursor, or its role not configured).</summary>
|
||||
NoNext,
|
||||
}
|
||||
|
||||
/// <summary>The rules of one walk over the pages of a profile, starting from the page on screen.</summary>
|
||||
@@ -143,22 +146,55 @@ public sealed partial class RecipeRunner
|
||||
var account = await LoadAccountAsync(run).ConfigureAwait(false);
|
||||
var (current, reads) = await OpenProfileAsync(run, account, waitForGrid: true).ConfigureAwait(false);
|
||||
account = current;
|
||||
var profile = AccountProfile(reads, account)!;
|
||||
await RecordCheckedProfileAsync(run, account, AccountProfile(reads, account)!, reads, highlights: true).ConfigureAwait(false);
|
||||
var (items, tailIsNew, fillGap) = await SaveFirstGridPageAsync(run, account, reads).ConfigureAwait(false);
|
||||
if (fillGap)
|
||||
{
|
||||
await FillGapAsync(run, account, reads, items, tailIsNew).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await Env.Driver.MaybeDistractionAsync(run.Ct).ConfigureAwait(false);
|
||||
return RecipeStatus.Completed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What a profile check keeps of the profile, whatever brought it: whether it has stories newer than the last
|
||||
/// look, the list of its highlight collections (when <paramref name="highlights"/>: the list was read), a copy of
|
||||
/// its picture when it changed.
|
||||
/// </summary>
|
||||
private async Task RecordCheckedProfileAsync(RecipeRun run, Account account, ProfileInfo profile, IReadOnlyList<CapturedRead> reads, bool highlights)
|
||||
{
|
||||
if (profile.LatestStoryAt is { } latest && latest > (account.LastStoriesCheckAt ?? DateTimeOffset.MinValue)
|
||||
&& account.ContentTypes.HasFlag(ContentTypes.Stories))
|
||||
{
|
||||
run.AccountsWithStories.Add(account.Id);
|
||||
}
|
||||
|
||||
var listed = reads.SelectMany(r => r.Result.Highlights).Where(h => h.Owner is null || h.Owner.Id == account.InstagramId).ToList();
|
||||
await Writer.UpsertHighlightsAsync(account, listed, run.Ct).ConfigureAwait(false);
|
||||
if (highlights)
|
||||
{
|
||||
await UpsertListedHighlightsAsync(run, account, reads).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if ((await Writer.SaveProfilePictureAsync(account, profile, run.Ct).ConfigureAwait(false)).Outcome == SaveOutcome.Created)
|
||||
{
|
||||
run.NewEntries++;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The highlight collections of the account that <paramref name="reads"/> list, stored.</summary>
|
||||
private Task UpsertListedHighlightsAsync(RecipeRun run, Account account, IReadOnlyList<CapturedRead> reads)
|
||||
{
|
||||
var listed = reads.SelectMany(r => r.Result.Highlights).Where(h => h.Owner is null || h.Owner.Id == account.InstagramId).ToList();
|
||||
return Writer.UpsertHighlightsAsync(account, listed, run.Ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the first page of the grid of a profile check, whatever brought it, and starts or ends the history when
|
||||
/// it has not started yet. Returns the items of the page, whether the last regular one was new, and whether the
|
||||
/// gap below the page is to be filled (the history has started or ended: <see cref="FillGapAsync"/>).
|
||||
/// </summary>
|
||||
private async Task<(IReadOnlyList<ContentItem> Items, bool TailIsNew, bool FillGap)> SaveFirstGridPageAsync(RecipeRun run, Account account, IReadOnlyList<CapturedRead> reads)
|
||||
{
|
||||
// The whole first page is read (it is on screen already): known posts at its top do not hide new ones below
|
||||
// them, e.g. when the giro dei seguiti saved only the newest. Pinned posts are known but stop nothing.
|
||||
var walk = ProfileWalk.Posts;
|
||||
@@ -197,14 +233,12 @@ public sealed partial class RecipeRunner
|
||||
await Env.Storage.Accounts.SetBackfillAsync(account.Id, null, Env.Clock.Now, run.Ct).ConfigureAwait(false);
|
||||
run.Finished = account.State == AccountState.Backfilling;
|
||||
}
|
||||
}
|
||||
else if (CollectionWriter.Wants(account, EntryKind.Post) && (account.BackfillCursor is not null || account.BackfillCompletedAt is not null))
|
||||
{
|
||||
await FillGapAsync(run, account, reads, items, tailIsNew: tail == SaveOutcome.Created).ConfigureAwait(false);
|
||||
|
||||
return (items, tail == SaveOutcome.Created, false);
|
||||
}
|
||||
|
||||
await Env.Driver.MaybeDistractionAsync(run.Ct).ConfigureAwait(false);
|
||||
return RecipeStatus.Completed;
|
||||
var fillGap = CollectionWriter.Wants(account, EntryKind.Post) && (account.BackfillCursor is not null || account.BackfillCompletedAt is not null);
|
||||
return (items, tail == SaveOutcome.Created, fillGap);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -313,37 +347,14 @@ public sealed partial class RecipeRunner
|
||||
private async Task<RecipeStatus> WalkAsync(RecipeRun run, ProfileWalk walk)
|
||||
{
|
||||
var account = await LoadAccountAsync(run).ConfigureAwait(false);
|
||||
if (!CollectionWriter.Wants(account, walk.Kind))
|
||||
if (await WalkStartAsync(run, account, walk).ConfigureAwait(false) is not { } start)
|
||||
{
|
||||
throw RecipeRun.Stop(RecipeStatus.Completed, walk.Kind == EntryKind.Tagged
|
||||
? $"«Post in cui è taggato» è spento per {account.Username}."
|
||||
: $"Foto e video dei post sono spenti per {account.Username}.");
|
||||
return RecipeStatus.Completed;
|
||||
}
|
||||
|
||||
var (cursor, checkOnly) = start;
|
||||
|
||||
var settings = Env.Storage.Settings;
|
||||
string? cursor;
|
||||
bool checkOnly;
|
||||
if (walk.IsGrid)
|
||||
{
|
||||
if (account.BackfillCompletedAt is not null)
|
||||
{
|
||||
run.Finished = true;
|
||||
return RecipeStatus.Completed;
|
||||
}
|
||||
|
||||
cursor = account.BackfillCursor;
|
||||
checkOnly = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
cursor = await settings.GetAsync(walk.CursorKey(account.Id), run.Ct).ConfigureAwait(false);
|
||||
checkOnly = await settings.GetAsync(walk.CompletedKey(account.Id), run.Ct).ConfigureAwait(false) is not null;
|
||||
if (checkOnly)
|
||||
{
|
||||
cursor = null;
|
||||
}
|
||||
}
|
||||
|
||||
var target = cursor is null ? null : ResumePoint.Parse(cursor, await settings.GetAsync(walk.MarkKey(account.Id), run.Ct).ConfigureAwait(false));
|
||||
if (!checkOnly)
|
||||
{
|
||||
@@ -406,6 +417,18 @@ public sealed partial class RecipeRunner
|
||||
Store = (next, last) => StoreWalkPointAsync(run, account, walk, next, last),
|
||||
}).ConfigureAwait(false);
|
||||
|
||||
await FinishWalkAsync(run, account, walk, end, checkOnly, caughtUp, catchUpPages).ConfigureAwait(false);
|
||||
return RecipeStatus.Completed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The end of a walk of Storico, Taggati or Reel, whatever turned its pages: at the beginning of the profile, or a
|
||||
/// history limit (not on a check-only walk), the walk is complete and its point cleared; when the stored point was
|
||||
/// not found again by scrolling, the timeline says so and the point stays.
|
||||
/// </summary>
|
||||
private async Task FinishWalkAsync(RecipeRun run, Account account, ProfileWalk walk, WalkEnd end, bool checkOnly, bool caughtUp, int catchUpPages)
|
||||
{
|
||||
var settings = Env.Storage.Settings;
|
||||
if (end == WalkEnd.EndOfList || (end == WalkEnd.Limit && !checkOnly))
|
||||
{
|
||||
run.Finished = true;
|
||||
@@ -438,8 +461,6 @@ public sealed partial class RecipeRunner
|
||||
run.Session.SessionId,
|
||||
run.Ct).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return RecipeStatus.Completed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -754,7 +775,23 @@ public sealed partial class RecipeRunner
|
||||
throw RecipeRun.Stop(RecipeStatus.Completed, EmptyPageMessage);
|
||||
}
|
||||
|
||||
var profile = AccountProfile(reads, account)!;
|
||||
account = await ApplyProfileStateAsync(run, account, AccountProfile(reads, account)!).ConfigureAwait(false);
|
||||
if (waitForGrid)
|
||||
{
|
||||
reads = await WaitForGridAsync(run, mark, account, reads).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return (account, reads);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What the profile just read says of the account, whatever brought it (the page or a request): a name now used by
|
||||
/// another account, private profile not followed (rule 6: not touched; both stop the run as
|
||||
/// <see cref="RecipeStatus.AccountUnreachable"/>), the facts of the profile, an unreachable account reachable again.
|
||||
/// Returns the updated account.
|
||||
/// </summary>
|
||||
private async Task<Account> ApplyProfileStateAsync(RecipeRun run, Account account, ProfileInfo profile)
|
||||
{
|
||||
if (account.InstagramId is { } known && profile.Id != known)
|
||||
{
|
||||
await MarkUnreachableAsync(run, account, UnreachableReason.Renamed).ConfigureAwait(false);
|
||||
@@ -776,12 +813,7 @@ public sealed partial class RecipeRunner
|
||||
account = await Env.Storage.Accounts.GetAsync(account.Id, run.Ct).ConfigureAwait(false) ?? account;
|
||||
}
|
||||
|
||||
if (waitForGrid)
|
||||
{
|
||||
reads = await WaitForGridAsync(run, mark, account, reads).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return (account, reads);
|
||||
return account;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in new issue
Block a user