diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 5cf81c1..0000000 --- a/.gitignore +++ /dev/null @@ -1,63 +0,0 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# Typescript v1 declaration files -typings/ - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env - -# next.js build output -.next - -dist/ diff --git a/MyWeatherSite-master/MyWeather.sln b/MyWeatherSite-master/MyWeather.sln new file mode 100644 index 0000000..7ec1ed2 --- /dev/null +++ b/MyWeatherSite-master/MyWeather.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.1169 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyWeather", "MyWeather\MyWeather.csproj", "{0D9042CE-3FDB-47DD-BAC3-EA2145DF12CA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0D9042CE-3FDB-47DD-BAC3-EA2145DF12CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0D9042CE-3FDB-47DD-BAC3-EA2145DF12CA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0D9042CE-3FDB-47DD-BAC3-EA2145DF12CA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0D9042CE-3FDB-47DD-BAC3-EA2145DF12CA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B6340110-57AA-4C6D-86ED-F2D314912286} + EndGlobalSection +EndGlobal diff --git a/MyWeatherSite-master/MyWeather/Models/WeatherData.cs b/MyWeatherSite-master/MyWeather/Models/WeatherData.cs new file mode 100644 index 0000000..3a91932 --- /dev/null +++ b/MyWeatherSite-master/MyWeather/Models/WeatherData.cs @@ -0,0 +1,89 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MyWeather +{ + public class Coord // координаты города + { + public double lon; // ширина + public double lat; // долгота + } + public class Wind + { + public double speed; // скорость ветра + public double deg; // направление ветра в град (метеорологическое) + public double gust; // порыв ветра + } + public class Rain + { + [JsonProperty("1h")] public double h1; // кол-во осадков за 1 час + [JsonProperty("3h")] public double h3; // кол-во осадков за 3 часа + } + public class Snow + { + [JsonProperty("1h")] public double h1; // кол-во осадков за 1 час + [JsonProperty("3h")] public double h3; // кол-во осадков за 3 часа + } + public class Sys + { + public string country; // код страны + public string sunrise; // восход солнца + public string sunset; // закат + } + public class Main + { + public double temp; // температура + public double feels_like; // как люди ощущают эту температуру + + public double pressure; // атмосферное давление + public double humidity; // влажность воздуха % + + public double temp_min; + public double temp_max; + + public double sea_level; // Атмосферное давление на уровне моря, гПа + public double grnd_level; // Атмосферное давление на уровне земли, гПа + } + public class Weather + { + public int id; // id типа погоды + public string main; // тип погоды (Дождь, Снег и т.д.) + public string description; // описание погоды + public string icon; // код значка погоды + } + public class Clouds + { + public double all; // облочность + } + + + + public class WeatherData + { + public static WeatherData instance; + + public string dt; // Время расчета данных, Unix, UTC + public int timezone; // Сдвиг в секундах от UTC + + public Sys sys; + public Main main; + public Coord coord; + public Wind wind; + public Snow snow; + public Rain rain; + public Clouds clouds; + public Weather[] weather; + + public int id; /// id города + public string name; // название города + + public WeatherData() + { + instance = this; + } + + } +} diff --git a/MyWeatherSite-master/MyWeather/MyWeather.csproj b/MyWeatherSite-master/MyWeather/MyWeather.csproj new file mode 100644 index 0000000..b56dcd8 --- /dev/null +++ b/MyWeatherSite-master/MyWeather/MyWeather.csproj @@ -0,0 +1,19 @@ + + + + netcoreapp2.1 + + + + + + + + + + + + + + + diff --git a/MyWeatherSite-master/MyWeather/Program.cs b/MyWeatherSite-master/MyWeather/Program.cs new file mode 100644 index 0000000..9147283 --- /dev/null +++ b/MyWeatherSite-master/MyWeather/Program.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Threading.Tasks; +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; + +namespace MyWeather +{ + public class Program + { + public static void Main(string[] args) + { + RequestSettings requestSettings = new RequestSettings(); + + HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(RequestSettings.Use.GetRequestString()); + + HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); + + string response; + + using (StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream())) + { + response = streamReader.ReadToEnd(); + } + + WeatherData weatherResponse = JsonConvert.DeserializeObject(response); + + CreateWebHostBuilder(args).Build().Run(); + } + + public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup(); + } +} diff --git a/MyWeatherSite-master/MyWeather/Properties/launchSettings.json b/MyWeatherSite-master/MyWeather/Properties/launchSettings.json new file mode 100644 index 0000000..350248c --- /dev/null +++ b/MyWeatherSite-master/MyWeather/Properties/launchSettings.json @@ -0,0 +1,27 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:1254", + "sslPort": 44336 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "MyWeather": { + "commandName": "Project", + "launchBrowser": true, + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} \ No newline at end of file diff --git a/MyWeatherSite-master/MyWeather/RequestSettings.cs b/MyWeatherSite-master/MyWeather/RequestSettings.cs new file mode 100644 index 0000000..bad8d75 --- /dev/null +++ b/MyWeatherSite-master/MyWeather/RequestSettings.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MyWeather +{ + public class RequestSettings + { + public static RequestSettings Use; + + private string url = "http://api.openweathermap.org/data/2.5/weather"; + private string city = "Иваново"; + private string appid = "a8934a33b74774a52a92e072ab3b4d55"; + private string lang = "en"; + private string units = "metric"; + + public RequestSettings() + { + Use = this; + } + + public string GetRequestString() + { + return $"{url}?q={city}&appid={appid}&lang={lang}&units={units}"; + } + + public string GetRequestString(string _city) + { + return $"{url}?q={_city}&appid={appid}&lang={lang}&units={units}"; + } + } +} diff --git a/MyWeatherSite-master/MyWeather/Startup.cs b/MyWeatherSite-master/MyWeather/Startup.cs new file mode 100644 index 0000000..0666658 --- /dev/null +++ b/MyWeatherSite-master/MyWeather/Startup.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; + +namespace MyWeather +{ + public class Startup + { + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc(); + } + + + public void Configure(IApplicationBuilder app, IHostingEnvironment env) + { + app.UseDeveloperExceptionPage(); // подключаем страницу с ошибками + app.UseStatusCodePages(); // показать коды страниц + app.UseStaticFiles(); // подключаем статические файлы + app.UseMvcWithDefaultRoute(); // отслеживание url адреса и активация url по умолчанию + + app.Run(async (context) => + { + await context.Response.WriteAsync( + $"City: {WeatherData.instance.name}\n" + + $"Temp: {WeatherData.instance.main.temp}\n" + + $"Description: {WeatherData.instance.weather[0].description}"); + }); + } + } +} diff --git a/MyWeatherSite-master/README.md b/MyWeatherSite-master/README.md new file mode 100644 index 0000000..047ed8e --- /dev/null +++ b/MyWeatherSite-master/README.md @@ -0,0 +1 @@ +# MyWeatherSite \ No newline at end of file