Skip to content

Commit

Permalink
Handle update to the bing image API
Browse files Browse the repository at this point in the history
  • Loading branch information
BlythMeister committed Feb 3, 2017
1 parent ae1a9e5 commit 3cb40c2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<configuration>
<appSettings>
<add key="ImageSavePath" value="G:\Bing Wallpaper"/>
<add key="ArchiveAfterMonths" value="2"/>
<add key="ArchiveAfterMonths" value="1"/>
<add key="PreventDuplicatesInArchive" value="True"/>
</appSettings>
<startup>
Expand Down
18 changes: 15 additions & 3 deletions src/BingInteractionAndParsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ internal static void GetBingImages()
var countryDuplicateImages = 0;
var currentIndex = 0;
var moreImages = true;
var startDate = string.Empty;
var endDate = string.Empty;
while (moreImages)
{
var xmlNodeList = GetImages(currentIndex, country.Name);
Expand All @@ -39,8 +41,19 @@ internal static void GetBingImages()
{
foreach (XmlNode xmlNode in xmlNodeList)
{
var nodeStartDate = xmlNode.SelectSingleNode("startdate").InnerText;
var nodeEndDate = xmlNode.SelectSingleNode("enddate").InnerText;

if (startDate == nodeStartDate && endDate == nodeEndDate)
{
moreImages = false;
break;
}

startDate = nodeStartDate;
endDate = nodeEndDate;
var imageUrl = $"{Url}{xmlNode.SelectSingleNode("urlBase").InnerText}_1920x1080.jpg";
ConsoleWriter.WriteLine(1, "Image for: '{0}' on {1}-{2} index {3} was: {4}", country.Name, xmlNode.SelectSingleNode("startdate").InnerText, xmlNode.SelectSingleNode("enddate").InnerText, currentIndex, imageUrl);
ConsoleWriter.WriteLine(1, "Image for: '{0}' on {1}-{2} index {3} was: {4}", country.Name, startDate, endDate, currentIndex, imageUrl);
try
{
if (DownloadAndSaveImage(xmlNode))
Expand All @@ -56,7 +69,6 @@ internal static void GetBingImages()
{
ConsoleWriter.WriteLine("There was an error getting image", ex);
}

}

currentIndex += 1;
Expand Down Expand Up @@ -104,7 +116,7 @@ internal static bool DownloadAndSaveImage(XmlNode xmlNode)
}

ConsoleWriter.WriteLine(2, "Downloaded Image, Checking If Duplicate");

var newImage = false;
if (!ImageHashing.ImageInHash(tempfilename) && !File.Exists(filePath))
{
Expand Down

0 comments on commit 3cb40c2

Please sign in to comment.