Add support for selecting Tumblr API credentials via CLI
Allows switching between multiple Tumblr API credential sets at runtime using new command-line arguments (-api3, -api4, -api [section]). API keys are now read from the selected section in appsettings.json, with validation for required keys. Also updates the SQL query for selecting blogs needing likes to use more precise filtering and ordering. Usage/help output is updated to reflect new options.
This commit is contained in:
@@ -21,6 +21,45 @@ namespace URLNotesGrabberCORE
|
||||
.Build();
|
||||
var settings = config.GetSection("appSettings");
|
||||
|
||||
string apiSectionName = "TumblrApi";
|
||||
List<string> filteredArgs = new List<string>();
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
{
|
||||
if (string.Equals(args[i], "-api3", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(args[i], "--api3", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
apiSectionName = "TumblrApi3";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.Equals(args[i], "-api4", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(args[i], "--api4", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
apiSectionName = "TumblrApi4";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.Equals(args[i], "-api", StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(args[i], "--api", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (i + 1 < args.Length && !string.IsNullOrWhiteSpace(args[i + 1]))
|
||||
{
|
||||
apiSectionName = args[i + 1].Trim();
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("--Missing API section after -api/--api. Using default TumblrApi.--");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
filteredArgs.Add(args[i]);
|
||||
}
|
||||
|
||||
args = filteredArgs.ToArray();
|
||||
APIAccess.SetApiConfigSection(apiSectionName);
|
||||
|
||||
// Setup Dual Logging
|
||||
string logPath = "console_output.log";
|
||||
if (File.Exists(logPath))
|
||||
@@ -77,6 +116,12 @@ namespace URLNotesGrabberCORE
|
||||
|
||||
Console.WriteLine("-likes\t Fetch likes for all blogs needing it (LikesPulled=0), or a specific blog via param");
|
||||
|
||||
Console.WriteLine("-api3\t Use TumblrApi3 settings from appsettings.json");
|
||||
|
||||
Console.WriteLine("-api4\t Use TumblrApi4 settings from appsettings.json");
|
||||
|
||||
Console.WriteLine("-api [section]\t Use a specific API settings section from appsettings.json (e.g. TumblrApi3)");
|
||||
|
||||
break;
|
||||
|
||||
case "-parse":
|
||||
|
||||
Reference in New Issue
Block a user