Download dev CRF2 with error handling
It frequently returns an empty 500
This commit is contained in:
parent
88d3ede9ff
commit
8d2a431a2a
2 changed files with 39 additions and 24 deletions
|
@ -7,7 +7,7 @@ public static class DownloadImages
|
||||||
{
|
{
|
||||||
public static async Task DoIt(HttpClient client)
|
public static async Task DoIt(HttpClient client)
|
||||||
{
|
{
|
||||||
foreach (var dir in Directory.EnumerateDirectories("my_robots"))
|
foreach (var dir in Directory.EnumerateDirectories("robots"))
|
||||||
{
|
{
|
||||||
var json = await File.ReadAllTextAsync(Path.Combine(dir, "metadata.json"));
|
var json = await File.ReadAllTextAsync(Path.Combine(dir, "metadata.json"));
|
||||||
var doc = JsonDocument.Parse(json);
|
var doc = JsonDocument.Parse(json);
|
||||||
|
|
|
@ -10,9 +10,7 @@ using RC2BotArchiver;
|
||||||
|
|
||||||
Console.WriteLine("Hello, World!");
|
Console.WriteLine("Hello, World!");
|
||||||
|
|
||||||
FixCRF2Archive.FixIt();
|
var client = new HttpClient();
|
||||||
|
|
||||||
/*var client = new HttpClient();
|
|
||||||
|
|
||||||
async Task<JsonElement?> GetResponse(HttpResponseMessage result, string url)
|
async Task<JsonElement?> GetResponse(HttpResponseMessage result, string url)
|
||||||
{
|
{
|
||||||
|
@ -24,6 +22,8 @@ async Task<JsonElement?> GetResponse(HttpResponseMessage result, string url)
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Status: " + result.StatusCode);
|
Console.WriteLine("Status: " + result.StatusCode);
|
||||||
|
if (result.StatusCode != HttpStatusCode.NoContent)
|
||||||
|
Console.WriteLine("Error: " + await result.Content.ReadAsStringAsync());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,33 +66,48 @@ var jwt = responseJson.Value.GetProperty("Token");
|
||||||
payload = new ExpandoObject();
|
payload = new ExpandoObject();
|
||||||
payload.Token = responseJson.Value.GetProperty("Token");
|
payload.Token = responseJson.Value.GetProperty("Token");
|
||||||
payload.ClientVersion = "100.0";
|
payload.ClientVersion = "100.0";
|
||||||
responseJson = await Post("https://progression.production.robocraft2.com/login/fj", payload);
|
responseJson = await Post("https://progression.development.robocraft.org/login/fj", payload);
|
||||||
var progressToken = responseJson.Value.GetProperty("token").GetString();
|
var progressToken = responseJson.Value.GetProperty("token").GetString();
|
||||||
|
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", progressToken);
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", progressToken);
|
||||||
|
|
||||||
const string factoryUrl = "https://factory.production.robocraft2.com";
|
const string factoryUrl = "https://factory.development.robocraft.org";
|
||||||
;
|
|
||||||
Console.WriteLine($"Getting owned robots");
|
int page = 52;
|
||||||
responseJson = await Get(factoryUrl + "/v1/foundry/garage");
|
while (true)
|
||||||
if (!responseJson.HasValue) throw new Exception("Failed to get robots!");
|
|
||||||
var results = responseJson.Value.GetProperty("vehicles");
|
|
||||||
foreach (var result in results.EnumerateArray())
|
|
||||||
{
|
{
|
||||||
var robot = result;
|
try
|
||||||
var dirPath = Path.Combine("my_robots", robot.GetProperty("id").GetString()!);
|
{
|
||||||
Directory.CreateDirectory(dirPath);
|
Console.WriteLine($"Getting page {page}");
|
||||||
File.WriteAllText(Path.Combine(dirPath, "metadata.json"), robot.GetRawText());
|
responseJson = await Get(factoryUrl + $"/v1/foundry/search?page={page}&count=10");
|
||||||
responseJson = await Get(factoryUrl + "/v1/foundry/vehicles/" + robot.GetProperty("id"));
|
if (!responseJson.HasValue) throw new Exception("Failed to get robots!");
|
||||||
if (!responseJson.HasValue) throw new Exception($"Could not get bot {robot.GetProperty("name")}");
|
var results = responseJson.Value.GetProperty("results");
|
||||||
File.WriteAllText(Path.Combine(dirPath, "robotData.json"), responseJson.Value.GetRawText());
|
if (results.GetArrayLength() == 0) break;
|
||||||
var data = responseJson.Value.GetProperty("data").GetString()!;
|
foreach (var result in results.EnumerateArray())
|
||||||
File.WriteAllBytes(Path.Combine(dirPath, "robot.rc2"), Convert.FromBase64String(data));
|
{
|
||||||
Console.WriteLine($"Saved {robot.GetProperty("name")} by {robot.GetProperty("creatorName")}");
|
var robot = result.GetProperty("robot");
|
||||||
Thread.Sleep(100);
|
var dirPath = Path.Combine("robots", robot.GetProperty("id").GetString()!);
|
||||||
|
Directory.CreateDirectory(dirPath);
|
||||||
|
File.WriteAllText(Path.Combine(dirPath, "metadata.json"), robot.GetRawText());
|
||||||
|
responseJson = await Get(factoryUrl + "/v1/foundry/vehicles/" + robot.GetProperty("id"));
|
||||||
|
if (!responseJson.HasValue) throw new Exception($"Could not get bot {robot.GetProperty("name")}");
|
||||||
|
File.WriteAllText(Path.Combine(dirPath, "robotData.json"), responseJson.Value.GetRawText());
|
||||||
|
Console.WriteLine($"Saved {robot.GetProperty("name")} by {robot.GetProperty("creatorName")}");
|
||||||
|
Thread.Sleep(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
page++;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
if (e.Message != "Failed to get robots!")
|
||||||
|
break;
|
||||||
|
Thread.Sleep(10000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await DownloadImages.DoIt(client);
|
await DownloadImages.DoIt(client);
|
||||||
|
|
||||||
// TODO: Chart of amount of bots on CRF by date & amount of starter bots
|
// TODO: Chart of amount of bots on CRF by date & amount of starter bots
|
||||||
*/
|
|
Loading…
Reference in a new issue