public static bool Region(string region) { string file = string.Empty; Console.Clear(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("***** ChaserAssistant - aktuellste Wochenvorhersage: " + region); Console.ForegroundColor = ConsoleColor.DarkCyan; if (region.ToLower() == "de") { file = GetFilenameOnServer(MainClass.RegionPathDictionary[region.ToLower()]); if (noerrors) { MainClass.dwdURL = MainClass.RegionPathDictionary[region.ToLower()] + file; TextOutput.Show(ReadText.GetWebsiteContent(MainClass.dwdURL)); noerrors = true; file = string.Empty; } } else { noerrors = false; } /* * switch (region) * { * case "DE": * case "de": * file = GetFilenameOnServer(MainClass.DE_PATH); * MainClass.dwdURL = MainClass.DE_PATH + file; * ReadText.GetWebsiteContent(MainClass.dwdURL); * TextOutput.Show(ReadText.GetWebsiteContent(MainClass.dwdURL)); * noerrors = true; * file = string.Empty; * break; * * default: * Console.WriteLine("Default ....: " + MainClass.dwdURL); * noerrors = false; * break; * } */ if (noerrors) { return(true); } else { return(false); } }
public static bool Landkreis(string lk) { string landkreis = string.Empty; if (lk.Length == 1) { landkreis = "_" + lk + "X"; } else { landkreis = "_" + lk; } StringBuilder warntexte = new StringBuilder(); Urls.Add(1, "https://opendata.dwd.de/weather/alerts/txt/GER/"); Urls.Add(2, "https://opendata.dwd.de/weather/alerts/txt/SU/"); Urls.Add(3, "https://opendata.dwd.de/weather/alerts/txt/MS/"); Urls.Add(4, "https://opendata.dwd.de/weather/alerts/txt/OF/"); Urls.Add(5, "https://opendata.dwd.de/weather/alerts/txt/PD/"); Urls.Add(6, "https://opendata.dwd.de/weather/alerts/txt/LZ/"); Urls.Add(7, "https://opendata.dwd.de/weather/alerts/txt/HA/"); Urls.Add(8, "https://opendata.dwd.de/weather/alerts/txt/EM/"); using (WebClient client = new WebClient()) { // next 2 lines are mainly for Windows: ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; client.Encoding = System.Text.Encoding.UTF7; client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"; foreach (var address in Urls) { try { // Sonderzeichen ausmerzen var data = client.DownloadData(address.Value); var encoded = System.Text.Encoding.UTF7.GetString(data); string noHTML = Regex.Replace(encoded, @"<[^>]+>| ", "").Trim(); string[] splitted = noHTML.Split(null); int counter = 0; for (int i = 0; i < splitted.Length; i++) { if (string.IsNullOrWhiteSpace(splitted[i])) { continue; } // WWHA50 scheinen Seegebietswarnungen zu sein else if (!splitted[i].StartsWith("WWHA50") && splitted[i].Contains(landkreis)) { counter++; //Console.WriteLine(counter.ToString() + " - " + address.Value + splitted[i]); Warnungen.Add(counter, address.Value + splitted[i]); } } //Console.WriteLine(noHTML); } catch (WebException we) { // WebException.Status holds useful information Console.WriteLine("WebException: " + we.Message + "\n" + we.Status.ToString() + "\nURL: " + MainClass.dwdURL); return(false); } catch (NotSupportedException ne) { // other errors Console.WriteLine("NotSupportedException: " + ne.Message); return(false); } } } if (Warnungen.Count > 0) { foreach (var warnung in Warnungen) { warntexte.AppendLine("------------------------------------------"); warntexte.Append(ReadText.GetWebsiteContent(warnung.Value)); //TextOutput.Show(warnung.Value); } Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("***** ChaserAssistant - aktuell gültige Warnungen für " + lk); Console.ForegroundColor = ConsoleColor.DarkCyan; TextOutput.Show(warntexte.ToString()); return(true); } else { Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("***** ChaserAssistant - keine Warnungen für übergebenes Kennzeichen gefunden"); return(false); } }
public static bool Region(string region) { //noerrors = false; string file = string.Empty; Console.Clear(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("***** ChaserAssistant - aktuellster Warnlagebricht Region: " + region); Console.ForegroundColor = ConsoleColor.DarkCyan; if (MainClass.RegionPathDictionary.ContainsKey(region.ToLower())) { file = GetFilenameOnServer(MainClass.RegionPathDictionary[region.ToLower()]); if (noerrors) { MainClass.dwdURL = MainClass.RegionPathDictionary[region.ToLower()] + file; TextOutput.Show(ReadText.GetWebsiteContent(MainClass.dwdURL)); // Sven // hier das noerrors Ergebnis von GetWebsiteContent prüfen! noerrors = true; file = string.Empty; } } else { noerrors = false; } /*switch (region) { case "DE": // ganz Deutschland case "de": file = GetFilenameOnServer(MainClass.DE_PATH); MainClass.dwdURL = MainClass.DE_PATH + file; TextOutput.Show(ReadText.GetWebsiteContent(MainClass.dwdURL)); noerrors = true; file = string.Empty; break; case "BW": // Baden-Württemberg case "bw": file = GetFilenameOnServer(MainClass.BW_PATH); MainClass.dwdURL = MainClass.BW_PATH + file; TextOutput.Show(ReadText.GetWebsiteContent(MainClass.dwdURL)); noerrors = true; file = string.Empty; break; case "BY": // Bayern case "by": file = GetFilenameOnServer(MainClass.BY_PATH); MainClass.dwdURL = MainClass.BY_PATH + file; TextOutput.Show(ReadText.GetWebsiteContent(MainClass.dwdURL)); noerrors = true; file = string.Empty; break; case "RPS": // Rheinland-Pfalz und Saarland case "rps": file = GetFilenameOnServer(MainClass.OF_PATH); MainClass.dwdURL = MainClass.OF_PATH + file; TextOutput.Show(ReadText.GetWebsiteContent(MainClass.dwdURL)); noerrors = true; file = string.Empty; break; case "HE": // Hessem case "he": file = GetFilenameOnServer(MainClass.OF_PATH); MainClass.dwdURL = MainClass.OF_PATH + file; TextOutput.Show(ReadText.GetWebsiteContent(MainClass.dwdURL)); noerrors = true; file = string.Empty; break; case "BB": // Berlin + Brandenburg case "bb": file = GetFilenameOnServer(MainClass.PD_PATH); MainClass.dwdURL = MainClass.PD_PATH + file; TextOutput.Show(ReadText.GetWebsiteContent(MainClass.dwdURL)); noerrors = true; file = string.Empty; break; case "MV": // Mecklenburg-Vorpommern case "mv": file = GetFilenameOnServer(MainClass.PD_PATH); MainClass.dwdURL = MainClass.PD_PATH + file; TextOutput.Show(ReadText.GetWebsiteContent(MainClass.dwdURL)); noerrors = true; file = string.Empty; break; case "SX": // Sachsen case "sx": file = GetFilenameOnServer(MainClass.LZ_PATH); MainClass.dwdURL = MainClass.LZ_PATH + file; TextOutput.Show(ReadText.GetWebsiteContent(MainClass.dwdURL)); noerrors = true; file = string.Empty; break; case "SA": // Sachsen-Anhalt case "sa": file = GetFilenameOnServer(MainClass.LZ_PATH); MainClass.dwdURL = MainClass.LZ_PATH + file; TextOutput.Show(ReadText.GetWebsiteContent(MainClass.dwdURL)); noerrors = true; file = string.Empty; break; case "TH": // Thüringen case "th": file = GetFilenameOnServer(MainClass.LZ_PATH); MainClass.dwdURL = MainClass.LZ_PATH + file; TextOutput.Show(ReadText.GetWebsiteContent(MainClass.dwdURL)); noerrors = true; file = string.Empty; break; case "NB": // Niedersachsen und Bremen case "nb": file = GetFilenameOnServer(MainClass.HA_PATH); MainClass.dwdURL = MainClass.HA_PATH + file; TextOutput.Show(ReadText.GetWebsiteContent(MainClass.dwdURL)); noerrors = true; file = string.Empty; break; case "SHH": // Schleswig-Holstein und Hamburg case "shh": file = GetFilenameOnServer(MainClass.HA_PATH); MainClass.dwdURL = MainClass.HA_PATH + file; TextOutput.Show(ReadText.GetWebsiteContent(MainClass.dwdURL)); noerrors = true; file = string.Empty; break; case "NRW": // Schleswig-Holstein und Hamburg case "nrw": file = GetFilenameOnServer(MainClass.EM_PATH); MainClass.dwdURL = MainClass.EM_PATH + file; TextOutput.Show(ReadText.GetWebsiteContent(MainClass.dwdURL)); noerrors = true; file = string.Empty; break; default: noerrors = false; break; }*/ if (noerrors) { return true; } else { return false; } }