From 7557c9a168326b595a0408dcc6d028402e2ffc85 Mon Sep 17 00:00:00 2001 From: jim Date: Mon, 19 Oct 2026 13:41:05 -0500 Subject: [PATCH] feat(likes): accept multiple blog names with --likes Change --likes from accepting a single blog name to accepting a list. Passes all non-flag args after --likes as blog names. Database stores bare blog names, so users pass just the name without .tumblr.com. Co-Authored-By: Claude --- URLNotesGrabberCORE/DataAccess.cs | 22 +++++++++++----------- URLNotesGrabberCORE/Program.cs | 16 +++++++++++----- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/URLNotesGrabberCORE/DataAccess.cs b/URLNotesGrabberCORE/DataAccess.cs index fb049bf..50ea16f 100644 --- a/URLNotesGrabberCORE/DataAccess.cs +++ b/URLNotesGrabberCORE/DataAccess.cs @@ -1341,7 +1341,7 @@ namespace URLNotesGrabberCORE return count; } - public static List> GetBlogsForLikes(string specificBlog = null, int cooldownDays = 7, bool ignoreCooldown = false, string? DBPath = null) + public static List> GetBlogsForLikes(List specificBlogs = null, int cooldownDays = 7, bool ignoreCooldown = false, string? DBPath = null) { DBPath ??= GetDefaultDbPath(); using SQLiteConnection connection = new SQLiteConnection("Data Source=" + DBPath); @@ -1352,19 +1352,16 @@ namespace URLNotesGrabberCORE connection.Open(); string sql; - // The two Notes branches below join on Blogs.BlogId, which is NULL for the 168k - // registry rows that have never appeared in a note. The inner join drops them, - // which is correct here -- both branches already require a note to exist -- but - // it is the wrong shape for anything that lists the registry. - if (!string.IsNullOrEmpty(specificBlog)) + if (specificBlogs != null && specificBlogs.Count > 0) { - // Specific blog: always process, bypass cooldown - sql = @"SELECT BlogName, + // Specific blogs: always process, bypass cooldown + var placeholders = string.Join(", ", specificBlogs.Select((_, i) => $"@blog{i}")); + sql = $@"SELECT BlogName, COALESCE(LikesPulled, 0), COALESCE(LikesCursor, 0), COALESCE(LikesNewestTimestamp, 0) FROM Blogs - WHERE BlogName = @blog + WHERE BlogName IN ({placeholders}) AND IsActive = 1"; } else if (ignoreCooldown) @@ -1405,8 +1402,11 @@ namespace URLNotesGrabberCORE using (SQLiteCommand command = new SQLiteCommand(sql, connection)) { - if (!string.IsNullOrEmpty(specificBlog)) - command.Parameters.AddWithValue("@blog", specificBlog); + if (specificBlogs != null && specificBlogs.Count > 0) + { + for (int i = 0; i < specificBlogs.Count; i++) + command.Parameters.AddWithValue($"@blog{i}", specificBlogs[i]); + } else if (!ignoreCooldown) command.Parameters.AddWithValue("@cooldownDays", cooldownDays); diff --git a/URLNotesGrabberCORE/Program.cs b/URLNotesGrabberCORE/Program.cs index a3e35cd..17fec05 100644 --- a/URLNotesGrabberCORE/Program.cs +++ b/URLNotesGrabberCORE/Program.cs @@ -415,9 +415,15 @@ namespace URLNotesGrabberCORE break; case "--likes": - string likeBlog = args.Length > 1 ? args[1] : null; + List likeBlogs = new List(); + for (int j = 1; j < args.Length; j++) + { + string arg = args[j]; + if (arg.StartsWith("--")) break; // stop at next flag + likeBlogs.Add(arg); + } int cooldownDays = settings.GetValue("LikesRefreshCooldownDays", 7); - CollectLikes(likeBlog, contains, cooldownDays, forceIgnoreCooldown).GetAwaiter().GetResult(); + CollectLikes(likeBlogs, contains, cooldownDays, forceIgnoreCooldown).GetAwaiter().GetResult(); break; case "--urldump": @@ -509,7 +515,7 @@ namespace URLNotesGrabberCORE Console.WriteLine("--replies\t Fetch and update missing reply text for all replies in database"); - Console.WriteLine("--likes\t Fetch likes: initial backfill for new blogs, incremental refresh for blogs past cooldown. Optional blog name forces single-blog run."); + Console.WriteLine("--likes [blog1 [blog2 ...]]\t Fetch likes: initial backfill for new blogs, incremental refresh for blogs past cooldown. One or more blog names restricts to those blogs."); Console.WriteLine("--force\t Ignore refresh cooldowns: with --likes, refresh every fully-backfilled blog; with --collect 1, re-queue already-collected posts without waiting out their cooldown"); @@ -913,14 +919,14 @@ namespace URLNotesGrabberCORE } } - static async Task CollectLikes(string specificBlog, List contains, int cooldownDays = 7, bool ignoreCooldown = false) + static async Task CollectLikes(List specificBlogs, List contains, int cooldownDays = 7, bool ignoreCooldown = false) { try { DataAccess.EnsureBlogsLikesColumnsExist(); Console.WriteLine($"Starting collection of likes... (cooldown {cooldownDays}d, ignoreCooldown={ignoreCooldown})"); - var blogsToProcess = DataAccess.GetBlogsForLikes(specificBlog, cooldownDays, ignoreCooldown); + var blogsToProcess = DataAccess.GetBlogsForLikes(specificBlogs, cooldownDays, ignoreCooldown); if (blogsToProcess.Count == 0) {