Created
October 9, 2018 09:42
-
-
Save soltys/c87161ed769c901f7839fbfe2827addf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Net; | |
namespace ConsoleApp20 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var start = new DateTime(2018, 9, 1); | |
var end = DateTime.Today; | |
var dates = GetDateRange(start, end); | |
var urls = GetUrls(dates); | |
foreach (var url in urls) | |
{ | |
using (WebClient wc = new WebClient()) | |
{ | |
var filePath = "temprature_" + url.Item2.ToString("dd-MM-yyyy") + ".png"; | |
wc.DownloadFile(url.Item1, filePath ); | |
} | |
} | |
} | |
private static IEnumerable<Tuple<string, DateTime>> GetUrls(IEnumerable<DateTime> dates) | |
{ | |
List<Tuple<string, DateTime>> urls = new List<Tuple<string, DateTime>>(); | |
foreach (var date in dates) | |
{ | |
var url = $"http://model.ocean.univ.gda.pl/images/" + date.ToString("dd-MM-yyyy") + "_00/S_0_T_small.png"; | |
urls.Add(Tuple.Create(url, date)); | |
} | |
return urls; | |
} | |
private static IEnumerable<DateTime> GetDateRange(DateTime start, DateTime end) | |
{ | |
var dates = new List<DateTime>(); | |
for (var dt = start; dt <= end; dt = dt.AddDays(1)) | |
{ | |
dates.Add(dt); | |
} | |
return dates; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment