forked from sim0n00ps/OF-DL
Extended "output blocked" to also include expired in separate file
This commit is contained in:
parent
65371702dd
commit
1d587eeccb
@ -414,7 +414,7 @@ public class APIHelper : IAPIHelper
|
||||
return await GetAllSubscriptions(getParams, endpoint, includeRestricted, config);
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, int>?> GetBlockedUsers(string endpoint, IDownloadConfig config, StatusContext ctx)
|
||||
public async Task<Dictionary<string, int>?> GetUsersWithProgress(string typeDisplay, string endpoint, StatusContext ctx, string? typeParam, bool offsetByCount)
|
||||
{
|
||||
int limit = 50;
|
||||
int offset = 0;
|
||||
@ -427,11 +427,14 @@ public class APIHelper : IAPIHelper
|
||||
["offset"] = offset.ToString()
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(typeParam))
|
||||
getParams["type"] = typeParam;
|
||||
|
||||
try
|
||||
{
|
||||
Dictionary<string, int> users = [];
|
||||
|
||||
Log.Debug("Calling GetBlockedUsers");
|
||||
Log.Debug("Calling GetUsersWithProgress");
|
||||
|
||||
bool isLastLoop = false;
|
||||
while (true)
|
||||
@ -443,10 +446,6 @@ public class APIHelper : IAPIHelper
|
||||
|
||||
Subscriptions? subscriptions = JsonConvert.DeserializeObject<Subscriptions>(body, m_JsonSerializerSettings);
|
||||
|
||||
ctx.Status($"[red]Getting Blocked Users\n[/] [red]Found {users.Count}[/]");
|
||||
ctx.Spinner(Spinner.Known.Dots);
|
||||
ctx.SpinnerStyle(Style.Parse("blue"));
|
||||
|
||||
if (subscriptions?.list is null)
|
||||
break;
|
||||
|
||||
@ -462,13 +461,20 @@ public class APIHelper : IAPIHelper
|
||||
users.Add(item.username, item.id);
|
||||
}
|
||||
|
||||
ctx.Status($"[red]Getting {typeDisplay} Users\n[/] [red]Found {users.Count}[/]");
|
||||
ctx.Spinner(Spinner.Known.Dots);
|
||||
ctx.SpinnerStyle(Style.Parse("blue"));
|
||||
|
||||
if (isLastLoop)
|
||||
break;
|
||||
|
||||
if (!subscriptions.hasMore || subscriptions.list.Count == 0)
|
||||
isLastLoop = true;
|
||||
|
||||
offset += subscriptions.list.Count;
|
||||
offset += offsetByCount
|
||||
? subscriptions.list.Count
|
||||
: limit;
|
||||
|
||||
getParams["offset"] = offset.ToString();
|
||||
}
|
||||
|
||||
|
@ -857,7 +857,7 @@ public class Program
|
||||
{
|
||||
if (config.OutputBlockedUsers)
|
||||
{
|
||||
await DownloadBlockedUsers(apiHelper, config);
|
||||
await DownloadBlockedOrExpiredUsers(apiHelper, config);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -887,28 +887,37 @@ public class Program
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task DownloadBlockedUsers(APIHelper m_ApiHelper, Entities.Config Config)
|
||||
private static async Task DownloadBlockedOrExpiredUsers(APIHelper m_ApiHelper, Entities.Config Config)
|
||||
{
|
||||
const string OUTPUT_FILE = "blocked-users.json";
|
||||
const string OUTPUT_FILE_BLOCKED = "blocked-users.json";
|
||||
const string OUTPUT_FILE_EXPIRED = "expired-users.json";
|
||||
|
||||
Dictionary<string, int>? blockedUsers = null;
|
||||
await GetUsers("Blocked", "/users/blocked", OUTPUT_FILE_BLOCKED);
|
||||
await GetUsers("Expired", "/subscriptions/subscribes", OUTPUT_FILE_EXPIRED, typeParam: "expired", offsetByCount: false);
|
||||
|
||||
await AnsiConsole
|
||||
.Status()
|
||||
.StartAsync("[red]Getting Blocked Users[/]", async ctx =>
|
||||
async Task GetUsers(string typeDisplay, string uri, string outputFile, string? typeParam = null, bool offsetByCount = true)
|
||||
{
|
||||
Dictionary<string, int>? users = null;
|
||||
|
||||
await AnsiConsole
|
||||
.Status()
|
||||
.StartAsync($"[red]Getting {typeDisplay} Users[/]", async ctx =>
|
||||
{
|
||||
users = await m_ApiHelper.GetUsersWithProgress(typeDisplay, uri, ctx, typeParam, offsetByCount);
|
||||
});
|
||||
|
||||
Console.WriteLine();
|
||||
|
||||
if (users is null || users.Count == 0)
|
||||
{
|
||||
blockedUsers = await m_ApiHelper.GetBlockedUsers("/users/blocked", Config, ctx);
|
||||
});
|
||||
|
||||
if (blockedUsers is null || blockedUsers.Count == 0)
|
||||
{
|
||||
AnsiConsole.Markup($"[green]No Blocked Users found.\n[/]");
|
||||
}
|
||||
else
|
||||
{
|
||||
AnsiConsole.Markup($"[green]Found {blockedUsers.Count} Blocked Users, saving to '{OUTPUT_FILE}'\n[/]");
|
||||
string json = JsonConvert.SerializeObject(blockedUsers, Formatting.Indented);
|
||||
await File.WriteAllTextAsync(OUTPUT_FILE, json);
|
||||
AnsiConsole.Markup($"[green]No {typeDisplay} Users found.\n[/]");
|
||||
}
|
||||
else
|
||||
{
|
||||
AnsiConsole.Markup($"[green]Found {users.Count} {typeDisplay} Users, saving to '{outputFile}'\n[/]");
|
||||
string json = JsonConvert.SerializeObject(users, Formatting.Indented);
|
||||
await File.WriteAllTextAsync(outputFile, json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user