Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 0 additions & 63 deletions .gitignore

This file was deleted.

25 changes: 25 additions & 0 deletions MyWeatherSite-master/MyWeather.sln
Original file line number Diff line number Diff line change
@@ -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
89 changes: 89 additions & 0 deletions MyWeatherSite-master/MyWeather/Models/WeatherData.cs
Original file line number Diff line number Diff line change
@@ -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;
}

}
}
19 changes: 19 additions & 0 deletions MyWeatherSite-master/MyWeather/MyWeather.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
<Folder Include="Controllers\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.7" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

</Project>
41 changes: 41 additions & 0 deletions MyWeatherSite-master/MyWeather/Program.cs
Original file line number Diff line number Diff line change
@@ -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<WeatherData>(response);

CreateWebHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
}
27 changes: 27 additions & 0 deletions MyWeatherSite-master/MyWeather/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
33 changes: 33 additions & 0 deletions MyWeatherSite-master/MyWeather/RequestSettings.cs
Original file line number Diff line number Diff line change
@@ -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}";
}
}
}
36 changes: 36 additions & 0 deletions MyWeatherSite-master/MyWeather/Startup.cs
Original file line number Diff line number Diff line change
@@ -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}");
});
}
}
}
1 change: 1 addition & 0 deletions MyWeatherSite-master/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# MyWeatherSite