Skip to content

Commit

Permalink
Updated code for user assets to use faster atom feeds
Browse files Browse the repository at this point in the history
  • Loading branch information
Kade-N committed Mar 26, 2021
1 parent 9f956b1 commit 53b2246
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/console/bin/Debug/net5.0/SporeDownloader.dll",
"args": [
"sporecast",
"501087975247"
"user",
"DOGC_Kyle"
],
"cwd": "${workspaceFolder}/console",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
Expand Down
33 changes: 13 additions & 20 deletions library/SporeUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,25 @@ public Queue<long> getAllAssetIds()

var assetIds = new Queue<long>();

for (int i = 0; ; i += 500)
{
var doc = server.getAssetsForUser(UserName, i, 500).Element("assets");
var doc = server.getAssetsForUserFeed(UserName).Element("{http://www.w3.org/2005/Atom}feed");

if(doc is null)
{
break;
}

foreach (var asset in doc.Elements("asset"))
if (doc is not null)
{
foreach (var asset in doc.Elements("{http://www.w3.org/2005/Atom}entry"))
{
long assetId = long.Parse(asset.Element("id")!.Value);
string entryId = asset.Element("{http://www.w3.org/2005/Atom}id")!.Value;
long assetId = long.Parse(entryId.Split('/')[1]);

assetIds.Enqueue(assetId);

Console.WriteLine($"Found asset ID {assetId} for user {UserName}");
}

// Check if the number of retrieved creations is less than 500, if it is, exit loop
int retrievedCount = int.Parse(doc.Element("count")!.Value);
if (retrievedCount < 500) break;
// Pause for a second, so we don't upset the server
else Thread.Sleep(1000);
Console.WriteLine($"Found {assetIds.Count} assets for user {UserName}");
}
else
{
Console.WriteLine($"Found no assets for user {UserName}, feed did not exist");
}

Console.WriteLine($"Found {assetIds.Count} assets for user {UserName}");

return assetIds;
}
Expand All @@ -78,14 +71,14 @@ public void downloadAllAssets(String filePath)
foreach (var id in assetIds)
{
server.downloadAssetPng(id, filePath + id + ".png");
try
/*try
{
server.getAssetInfo(id).Save(filePath + id + "_meta.xml");
}
catch (System.Xml.XmlException)
{
Console.WriteLine($"Asset ID {id} for user {UserName} has invalid data in its Spore.com XML data, this data will not be saved");
}
}*/

Console.WriteLine($"Saved asset ID {id} for user {UserName}");
}
Expand Down

0 comments on commit 53b2246

Please sign in to comment.