Skip to content

Commit

Permalink
Added counter to incidate how many downloads have happened and remove…
Browse files Browse the repository at this point in the history
…d delay after every download.
  • Loading branch information
malfunct committed Aug 5, 2023
1 parent 709f257 commit 4c878fd
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions SyncCollection/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,20 @@ private static void ArchiveOldDownloadList(string collection)
string resourceBase = "https://archive.org/compress";
WebClient client = new WebClient();

int count = 0;

foreach (var indicatorToDownload in searchResults.Keys)
{
if (!localFileList.ContainsKey(indicatorToDownload) || searchResults[indicatorToDownload] >
localFileList[indicatorToDownload])
{
count++;
currentlyDownloading = $"{collection}/{indicatorToDownload}.zip";

var url = $"{resourceBase}/{indicatorToDownload}";

Console.WriteLine($"Downloading {currentlyDownloading}");
Console.WriteLine($"Downloading from {url}");
Console.WriteLine($"{count}: Downloading {currentlyDownloading}");
Console.WriteLine($"{count}: Downloading from {url}");

bool success = false;
try
Expand All @@ -98,7 +101,7 @@ private static void ArchiveOldDownloadList(string collection)
{
// Just skip webexceptions and clean up so we can
// download as much of the collection as possible
Console.WriteLine($"Error while downloading {e.Message}");
Console.WriteLine($"{count}: Error while downloading {e.Message}");

// delete failed download
if (File.Exists(currentlyDownloading))
Expand All @@ -116,7 +119,6 @@ private static void ArchiveOldDownloadList(string collection)

UpdateLocalFileList(updatedFileList, collection); //we churn this file a lot so we don't lose much state if process interrupted
}
System.Threading.Thread.Sleep(500); //forcing a sleep to be nice to archive.org?
}
}
}
Expand Down

0 comments on commit 4c878fd

Please sign in to comment.