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);
|
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 limit = 50;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
@ -427,11 +427,14 @@ public class APIHelper : IAPIHelper
|
|||||||
["offset"] = offset.ToString()
|
["offset"] = offset.ToString()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(typeParam))
|
||||||
|
getParams["type"] = typeParam;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Dictionary<string, int> users = [];
|
Dictionary<string, int> users = [];
|
||||||
|
|
||||||
Log.Debug("Calling GetBlockedUsers");
|
Log.Debug("Calling GetUsersWithProgress");
|
||||||
|
|
||||||
bool isLastLoop = false;
|
bool isLastLoop = false;
|
||||||
while (true)
|
while (true)
|
||||||
@ -443,10 +446,6 @@ public class APIHelper : IAPIHelper
|
|||||||
|
|
||||||
Subscriptions? subscriptions = JsonConvert.DeserializeObject<Subscriptions>(body, m_JsonSerializerSettings);
|
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)
|
if (subscriptions?.list is null)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -462,13 +461,20 @@ public class APIHelper : IAPIHelper
|
|||||||
users.Add(item.username, item.id);
|
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)
|
if (isLastLoop)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (!subscriptions.hasMore || subscriptions.list.Count == 0)
|
if (!subscriptions.hasMore || subscriptions.list.Count == 0)
|
||||||
isLastLoop = true;
|
isLastLoop = true;
|
||||||
|
|
||||||
offset += subscriptions.list.Count;
|
offset += offsetByCount
|
||||||
|
? subscriptions.list.Count
|
||||||
|
: limit;
|
||||||
|
|
||||||
getParams["offset"] = offset.ToString();
|
getParams["offset"] = offset.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -857,7 +857,7 @@ public class Program
|
|||||||
{
|
{
|
||||||
if (config.OutputBlockedUsers)
|
if (config.OutputBlockedUsers)
|
||||||
{
|
{
|
||||||
await DownloadBlockedUsers(apiHelper, config);
|
await DownloadBlockedOrExpiredUsers(apiHelper, config);
|
||||||
return;
|
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);
|
||||||
|
|
||||||
|
async Task GetUsers(string typeDisplay, string uri, string outputFile, string? typeParam = null, bool offsetByCount = true)
|
||||||
|
{
|
||||||
|
Dictionary<string, int>? users = null;
|
||||||
|
|
||||||
await AnsiConsole
|
await AnsiConsole
|
||||||
.Status()
|
.Status()
|
||||||
.StartAsync("[red]Getting Blocked Users[/]", async ctx =>
|
.StartAsync($"[red]Getting {typeDisplay} Users[/]", async ctx =>
|
||||||
{
|
{
|
||||||
blockedUsers = await m_ApiHelper.GetBlockedUsers("/users/blocked", Config, ctx);
|
users = await m_ApiHelper.GetUsersWithProgress(typeDisplay, uri, ctx, typeParam, offsetByCount);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (blockedUsers is null || blockedUsers.Count == 0)
|
Console.WriteLine();
|
||||||
|
|
||||||
|
if (users is null || users.Count == 0)
|
||||||
{
|
{
|
||||||
AnsiConsole.Markup($"[green]No Blocked Users found.\n[/]");
|
AnsiConsole.Markup($"[green]No {typeDisplay} Users found.\n[/]");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AnsiConsole.Markup($"[green]Found {blockedUsers.Count} Blocked Users, saving to '{OUTPUT_FILE}'\n[/]");
|
AnsiConsole.Markup($"[green]Found {users.Count} {typeDisplay} Users, saving to '{outputFile}'\n[/]");
|
||||||
string json = JsonConvert.SerializeObject(blockedUsers, Formatting.Indented);
|
string json = JsonConvert.SerializeObject(users, Formatting.Indented);
|
||||||
await File.WriteAllTextAsync(OUTPUT_FILE, json);
|
await File.WriteAllTextAsync(outputFile, json);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user