commit 38a183910aa11398cc984a1af0ed6d83ecd4ffe2
Author: Eliška Mourycová <eliska.mourycova@seznam.cz>
Date:   Fri Jun 4 20:42:43 2021 +0200

    Re #9007. Added weather prediction website to the config file + modified method for weather predictoin download.

diff --git a/Server/ServerApp/DataDownload/DataDownloader.cs b/Server/ServerApp/DataDownload/DataDownloader.cs
index 7d2b59f..bee3ddc 100644
--- a/Server/ServerApp/DataDownload/DataDownloader.cs
+++ b/Server/ServerApp/DataDownload/DataDownloader.cs
@@ -51,6 +51,9 @@ namespace ServerApp.DataDownload
 		// the main site where the data can be downloaded from
 		private string site;
 
+		// weather prediction site
+		private string weatherPredictionSite;
+
 		// the substring at the start of every file name
 		private string dataStr;
 
@@ -65,12 +68,13 @@ namespace ServerApp.DataDownload
 		private List<string> variablesInsertions;
 		private List<char> nameTurns;
 
-		public DataDownloader(string rootDataDir, string website, string namingConvention) // todo: take naming conventons specifiaction into account
+		public DataDownloader(string rootDataDir, string website, string namingConvention, string weatherPredSite) // todo: take naming conventons specifiaction into account
 		{
 			// initialize all needed variables:
 
 			//Console.WriteLine(Directory.GetCurrentDirectory());
 			site = website;//"http://openstore.zcu.cz/";
+			weatherPredictionSite = weatherPredSite;
 
 			ParseNaming(namingConvention);
 			dataStr = "OD_ZCU_";
@@ -91,13 +95,23 @@ namespace ServerApp.DataDownload
 		public string DownloadWeatherPrediction()
 		{
 			// TODO either set this path as attribute or if parameter JsonParser needs an attribute that would be set through constructor
-			string predictionSite = "http://wttr.in/Plzen,czechia?format=j1";
-
-			DateTime now = DateTime.Now;
-			WebClient webClient = new WebClient();
-			webClient.DownloadFile(predictionSite, $"data/{now.Year}{now.Month}{now.Day}.json");
+			//string predictionSite = "http://wttr.in/Plzen,czechia?format=j1";
 
-			return $"data/{now.Year}{now.Month}{now.Day}.json";
+			//DateTime now = DateTime.Now;
+			//WebClient webClient = new WebClient();
+			//webClient.DownloadFile(predictionSite, $"data/{now.Year}{now.Month}{now.Day}.json");
+			
+			try
+			{
+				return webClient.DownloadString(weatherPredictionSite);// $"data/{now.Year}{now.Month}{now.Day}.json";
+			}
+			catch(Exception e)
+			{
+				// this shouldn't happen
+				Console.WriteLine("Weather prediction download failed!");
+				return null;
+			}
+			
 		}
 
 		/// <summary>
@@ -223,7 +237,7 @@ namespace ServerApp.DataDownload
 						case "format":
 							add = "" + format;
 							break;
-						default: throw new Exception("Config file error - naming conventions can only contain variables with following names: type, month, year, format");
+						default: throw new Exception("Config file error - naming conventions can only contain variables with the following names: type, month, year, format");
 					}
 					nameZip += add;
 					varInd++;
diff --git a/Server/ServerApp/Program.cs b/Server/ServerApp/Program.cs
index f6046ec..c5d629b 100644
--- a/Server/ServerApp/Program.cs
+++ b/Server/ServerApp/Program.cs
@@ -21,6 +21,7 @@ namespace ServerApp
 		public string DataWebsite { get; set; }
 		public string DownloadedFilesNaming { get; set; }
 		public string DataRootDir { get; set; }
+		public string WeatherSite { get; set; }
 		public string Port { get; set; } // TODO port cannot be configurable?
 	}
 
@@ -46,6 +47,9 @@ namespace ServerApp
 			// data download test
 			DataDownloader dd = DataDownloadAndRetrievalTest(config);
 
+			WeatherAsStringTest(dd);
+			Console.ReadLine();
+
 			// xml building test
 			//XMLTest();
 
@@ -77,7 +81,7 @@ namespace ServerApp
 		private static DataDownloader DataDownloadAndRetrievalTest(Config config)
 		{
 			//test scenario -data download:
-			DataDownloader dd = new DataDownloader(config.DataRootDir, config.DataWebsite, config.DownloadedFilesNaming);
+			DataDownloader dd = new DataDownloader(config.DataRootDir, config.DataWebsite, config.DownloadedFilesNaming, config.WeatherSite);
 			dd.OverwriteExisting = false;
 			List<string> savedFiles = new List<string>();
 
@@ -158,6 +162,11 @@ namespace ServerApp
 				Console.WriteLine(w.ToString());
 		}
 
+		private static void WeatherAsStringTest(DataDownloader dd)
+		{
+			Console.WriteLine(dd.DownloadWeatherPrediction());
+		}
+
 		private static IPredictionController PredictionTest(DataDownloader dd)
 		{
 			// TODO nastavit čas
@@ -227,6 +236,9 @@ namespace ServerApp
 						rootPath = Path.GetFullPath(rootPath);
 						extractedConfigInfo.DataRootDir = rootPath;
 						break;
+					case "!weather_site!":
+						extractedConfigInfo.WeatherSite = lines[++i].Trim();
+						break;
 					case "!port!":
 						extractedConfigInfo.Port = lines[++i].Trim();
 						break;
diff --git a/Server/ServerApp/Properties/launchSettings.json b/Server/ServerApp/Properties/launchSettings.json
index c5a1967..c5b461c 100644
--- a/Server/ServerApp/Properties/launchSettings.json
+++ b/Server/ServerApp/Properties/launchSettings.json
@@ -2,7 +2,7 @@
   "profiles": {
     "ServerApp": {
       "commandName": "Project",
-      "commandLineArgs": "C:\\Users\\kalivoda\\University\\KIV-ASWI\\aswi2021tri-musketyri\\Server\\ServerApp\\server_config"
+      "commandLineArgs": "C:\\Users\\elisk\\Documents\\aswi2021tri-musketyri\\Server\\ServerApp\\server_config"
     }
   }
 }
\ No newline at end of file
diff --git a/Server/ServerApp/server_config b/Server/ServerApp/server_config
index ef70b07..73e1807 100644
--- a/Server/ServerApp/server_config
+++ b/Server/ServerApp/server_config
@@ -1,10 +1,10 @@
 #
 # Tri Musketyri, ASWI 2021
-# This is the server configuration file. See [wiki_site] for detailed information about its structure.
+# This is the server configuration file. See the documentation for detailed information about its structure.
 # Pass this file as an argument to the server program when launching it.
 #
 
-# --- DATA DOWNLOADING CONFIGURATION ---
+# --- DATA FILES DOWNLOADING CONFIGURATION ---
 
 # the main website containing all data:
 !site!
@@ -21,6 +21,11 @@ OD_ZCU_{type}_{month}_{year}_{format}.zip
 !data_root_dir!
 .\data\auto
 
+# --- (future) WEATHER PREDICTION DOWNLOADING CONFIGURATION ---
+# the url to download from - must contain data in specific format, see documentation for details
+!weather_site!
+http://wttr.in/Plzen,czechia?format=j1
+
 
 # --- CONNECTION CONFIGURATION ---
 
