public void Test_Download_GrabberListCSV() { string url = "https://raw.githubusercontent.com/swharden/QRSSplus/master/grabbers.csv"; Grabber[] grabbers = GrabberIO.GrabbersFromCsvUrl(url).Result; Assert.Greater(grabbers.Length, 20); }
public void Test_Status_GrabbersFromJson() { string json = File.ReadAllText(SampleData.GRABBERSTATUS_JSON_PATH); Grabber[] grabbers = GrabberIO.GrabbersFromJson(json); Assert.AreEqual(SampleData.GRABBERSTATUS_JSON_COUNT, grabbers.Count()); }
/// <summary> /// Read the JSON status file to update the history of the given grabbers /// </summary> private static void UpdateGrabberHistory(Grabber[] grabbers, BlobContainerClient container, ILogger log) { log.LogInformation($"reading information from stored grabber file: {GRABBERS_JSON_FILENAME}"); BlobClient blob = container.GetBlobClient(GRABBERS_JSON_FILENAME); if (!blob.Exists()) { return; } using MemoryStream stream = new MemoryStream(); blob.DownloadTo(stream); string json = Encoding.UTF8.GetString(stream.ToArray()); Grabber[] oldGrabbers = GrabberIO.GrabbersFromJson(json); Dictionary <string, Grabber> oldGrabberDictionary = new Dictionary <string, Grabber>(); foreach (Grabber oldGrabber in oldGrabbers) { if (oldGrabberDictionary.ContainsKey(oldGrabber.Info.ID)) { oldGrabberDictionary.Remove(oldGrabber.Info.ID); } oldGrabberDictionary.Add(oldGrabber.Info.ID, oldGrabber); } foreach (Grabber grabber in grabbers.Where(x => oldGrabberDictionary.ContainsKey(x.Info.ID))) { grabber.History.Update(oldGrabberDictionary[grabber.Info.ID].History); } log.LogInformation($"read information about {grabbers.Length} grabbers"); }
public void Test_Status_GrabbersToJson() { Grabber[] grabbers = GrabberIO.GrabbersFromCsvFile(SampleData.GRABBERS_CSV_PATH); string json = GrabberIO.GrabbersToJson(grabbers); Console.WriteLine(json); Assert.Greater(json.Length, 1000); }
/// <summary> /// Read the grabber list to get the latest grabber information /// </summary> private static Grabber[] GetGrabbers(ILogger log, int maximumCount = 999) { string grabberCsvUrl = "https://raw.githubusercontent.com/swharden/QRSSplus/master/grabbers.csv"; int linuxTime = (int)DateTime.Now.Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds; grabberCsvUrl += $"?v={linuxTime}"; log.LogInformation($"getting list of grabbers from: {grabberCsvUrl}"); Grabber[] grabbers = GrabberIO.GrabbersFromCsvUrl(grabberCsvUrl).Result; return(grabbers.Take(maximumCount).ToArray()); }
public void Test_Download_ImageData() { Grabber[] grabbers = GrabberIO.GrabbersFromCsvFile(SampleData.GRABBERS_CSV_PATH); DateTime dt = DateTime.UtcNow; Parallel.ForEach(grabbers, grabber => { grabber.DownloadLatestGrab(dt); Console.WriteLine(grabber); }); string json = GrabberIO.GrabbersToJson(grabbers); File.WriteAllText("grabberStatus.json", json); }
/// <summary> /// Create a JSON summary of all grabbers and save it as a flat file in blob storage /// </summary> private static void SaveStatusFile(Grabber[] grabbers, BlobContainerClient container, ILogger log) { log.LogInformation($"saving {GRABBERS_JSON_FILENAME}"); string json = GrabberIO.GrabbersToJson(grabbers); byte[] jsonBytes = Encoding.UTF8.GetBytes(json); BlobClient blob = container.GetBlobClient(GRABBERS_JSON_FILENAME); using var stream = new MemoryStream(jsonBytes, writable: false); blob.Upload(stream, overwrite: true); BlobHttpHeaders headers = new BlobHttpHeaders { ContentType = "text/plain", ContentLanguage = "en-us" }; blob.SetHttpHeaders(headers); }
public static void Test_GrabberListCSV_CanBeParsed() { Grabber[] grabbers = GrabberIO.GrabbersFromCsvFile(GRABBERS_CSV_PATH); Assert.AreEqual(GRABBERS_CSV_COUNT, grabbers.Length); }