Created a sloppy api for home weather
This commit is contained in:
25
.dockerignore
Normal file
25
.dockerignore
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
**/.dockerignore
|
||||||
|
**/.env
|
||||||
|
**/.git
|
||||||
|
**/.gitignore
|
||||||
|
**/.project
|
||||||
|
**/.settings
|
||||||
|
**/.toolstarget
|
||||||
|
**/.vs
|
||||||
|
**/.vscode
|
||||||
|
**/.idea
|
||||||
|
**/*.*proj.user
|
||||||
|
**/*.dbmdl
|
||||||
|
**/*.jfm
|
||||||
|
**/azds.yaml
|
||||||
|
**/bin
|
||||||
|
**/charts
|
||||||
|
**/docker-compose*
|
||||||
|
**/Dockerfile*
|
||||||
|
**/node_modules
|
||||||
|
**/npm-debug.log
|
||||||
|
**/obj
|
||||||
|
**/secrets.dev.yaml
|
||||||
|
**/values.dev.yaml
|
||||||
|
LICENSE
|
||||||
|
README.md
|
||||||
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
/packages/
|
||||||
|
riderModule.iml
|
||||||
|
/_ReSharper.Caches/
|
||||||
13
.idea/.idea.HomeApi/.idea/.gitignore
generated
vendored
Normal file
13
.idea/.idea.HomeApi/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Rider ignored files
|
||||||
|
/contentModel.xml
|
||||||
|
/projectSettingsUpdater.xml
|
||||||
|
/.idea.HomeApi.iml
|
||||||
|
/modules.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
4
.idea/.idea.HomeApi/.idea/encodings.xml
generated
Normal file
4
.idea/.idea.HomeApi/.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||||
|
</project>
|
||||||
8
.idea/.idea.HomeApi/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.HomeApi/.idea/indexLayout.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="UserContentModel">
|
||||||
|
<attachedFolders />
|
||||||
|
<explicitIncludes />
|
||||||
|
<explicitExcludes />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/.idea.HomeApi/.idea/vcs.xml
generated
Normal file
6
.idea/.idea.HomeApi/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
21
Dockerfile
Normal file
21
Dockerfile
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
FROM mcr.microsoft.com/dotnet/runtime:9.0 AS base
|
||||||
|
USER $APP_UID
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
WORKDIR /src
|
||||||
|
COPY ["HomeApi.csproj", "./"]
|
||||||
|
RUN dotnet restore "HomeApi.csproj"
|
||||||
|
COPY . .
|
||||||
|
WORKDIR "/src/"
|
||||||
|
RUN dotnet build "./HomeApi.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||||
|
|
||||||
|
FROM build AS publish
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
RUN dotnet publish "./HomeApi.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||||
|
|
||||||
|
FROM base AS final
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=publish /app/publish .
|
||||||
|
ENTRYPOINT ["dotnet", "HomeApi.dll"]
|
||||||
11
HomeApi.csproj
Normal file
11
HomeApi.csproj
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
24
HomeApi.sln
Normal file
24
HomeApi.sln
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FF03E920-D5E9-4BE0-AA6F-DB2E9287D3E4}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
compose.yaml = compose.yaml
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HomeApi", "HomeApi\HomeApi.csproj", "{0F340BDE-7B8E-4ACD-8A24-5B5BFFB424F4}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{0F340BDE-7B8E-4ACD-8A24-5B5BFFB424F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{0F340BDE-7B8E-4ACD-8A24-5B5BFFB424F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{0F340BDE-7B8E-4ACD-8A24-5B5BFFB424F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{0F340BDE-7B8E-4ACD-8A24-5B5BFFB424F4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(NestedProjects) = preSolution
|
||||||
|
{0F340BDE-7B8E-4ACD-8A24-5B5BFFB424F4} = {FF03E920-D5E9-4BE0-AA6F-DB2E9287D3E4}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
149
HomeApi/Controllers/HomeController.cs
Normal file
149
HomeApi/Controllers/HomeController.cs
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
using System.Text.Json;
|
||||||
|
using HomeApi.Models;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
|
namespace HomeApi.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("[controller]")]
|
||||||
|
public class HomeController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ILogger<HomeController> _logger;
|
||||||
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
|
|
||||||
|
// get configuration from appsettings.json
|
||||||
|
private readonly ApiConfiguration _apiConfiguration;
|
||||||
|
|
||||||
|
public HomeController(ILogger<HomeController> logger, IHttpClientFactory httpClientFactory, IOptions<ApiConfiguration> apiConfiguration)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_apiConfiguration = apiConfiguration.Value;
|
||||||
|
_httpClientFactory = httpClientFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet(Name = "GetHome")]
|
||||||
|
public async Task<Home> Get()
|
||||||
|
{
|
||||||
|
var client = _httpClientFactory.CreateClient();
|
||||||
|
var cordinates = await GetCoordinatesAsync(_apiConfiguration.DefaultCity);
|
||||||
|
var auroraJson = await client.GetStringAsync($"http://api.auroras.live/v1/?type=all&lat={cordinates.Value.Latitude}&long={cordinates.Value.Longitude}&forecast=false&threeday=false");
|
||||||
|
var auroraForecast = JsonSerializer.Deserialize<AuroraForecast>(auroraJson);
|
||||||
|
|
||||||
|
var url =
|
||||||
|
$"{_apiConfiguration.BaseUrls.Weather}/forecast.json?key={_apiConfiguration.Keys.Weather}&q={cordinates.Value.Latitude},{cordinates.Value.Longitude}&days=7&lang=sv&aqi=yes&alerts=yes";
|
||||||
|
var response = await client.GetAsync(url);
|
||||||
|
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
|
var json = await response.Content.ReadAsStringAsync();
|
||||||
|
var weather = JsonSerializer.Deserialize<WeatherData>(json, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||||
|
|
||||||
|
var forecasts = weather.Forecast.Forecastday.Select(day => new Models.Forecast
|
||||||
|
{
|
||||||
|
Date = day.Date,
|
||||||
|
MaxTempC = day.Day.Maxtemp_C,
|
||||||
|
MinTempC = day.Day.Mintemp_C,
|
||||||
|
DayIcon = day.Day.Condition.Icon,
|
||||||
|
Astro = new Models.Astro {
|
||||||
|
Moon_Illumination = day.Astro.Moon_Illumination,
|
||||||
|
Moon_Phase = day.Astro.Moon_Phase,
|
||||||
|
Moonrise = day.Astro.Moonrise,
|
||||||
|
Moonset = day.Astro.Moonset,
|
||||||
|
Sunrise = day.Astro.Sunrise,
|
||||||
|
Sunset = day.Astro.Sunset
|
||||||
|
},
|
||||||
|
Day = MapSummary(day.Hour.Where(h => h.Is_Day == 1)),
|
||||||
|
Night = MapSummary(day.Hour.Where(h => h.Is_Day == 0))
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
var result = new Home
|
||||||
|
{
|
||||||
|
CityName = cordinates.Value.name,
|
||||||
|
Current = new Models.Current
|
||||||
|
{
|
||||||
|
Date = DateTime.Now.ToString(CultureInfo.CurrentCulture),
|
||||||
|
Feelslike = weather.Current.Feelslike_C,
|
||||||
|
IsDay = weather.Current.Is_Day,
|
||||||
|
WindPerHour = weather.Current.Wind_Kph,
|
||||||
|
WindGustPerHour = weather.Current.Gust_Kph,
|
||||||
|
Temperature = weather.Current.Temp_C,
|
||||||
|
AuroraProbability = new Probability
|
||||||
|
{
|
||||||
|
Date = auroraForecast.Date,
|
||||||
|
Calculated = new Models.CalculatedProbability
|
||||||
|
{
|
||||||
|
Value = auroraForecast.Probability.Calculated.Value,
|
||||||
|
Colour = auroraForecast.Probability.Calculated.Colour,
|
||||||
|
Lat = auroraForecast.Probability.Calculated.Lat,
|
||||||
|
Long = auroraForecast.Probability.Calculated.Long
|
||||||
|
},
|
||||||
|
Colour = auroraForecast.Probability.Colour,
|
||||||
|
Value = auroraForecast.Probability.Value,
|
||||||
|
HighestProbability = new Highest
|
||||||
|
{
|
||||||
|
Colour = auroraForecast.Probability.Highest.Colour,
|
||||||
|
Lat = auroraForecast.Probability.Highest.Lat,
|
||||||
|
Long = auroraForecast.Probability.Highest.Long,
|
||||||
|
Value = auroraForecast.Probability.Highest.Value,
|
||||||
|
Date = auroraForecast.Probability.Highest.Date
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Forecast = forecasts,
|
||||||
|
};
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private WeatherSummary MapSummary(IEnumerable<Hour> hours)
|
||||||
|
{
|
||||||
|
if (!hours.Any())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new WeatherSummary
|
||||||
|
{
|
||||||
|
ConditionText = hours.GroupBy(h => h.Condition.Text).OrderByDescending(g => g.Count()).First().Key,
|
||||||
|
ConditionIcon = hours.GroupBy(h => h.Condition.Icon).OrderByDescending(g => g.Count()).First().Key,
|
||||||
|
AvgTempC = Math.Round(hours.Average(h => h.Temp_C), 1),
|
||||||
|
AvgFeelslikeC = Math.Round(hours.Average(h => h.Feelslike_C), 1),
|
||||||
|
TotalChanceOfRain = (int)Math.Round(hours.Average(h => h.Chance_Of_Rain)),
|
||||||
|
TotalChanceOfSnow = (int)Math.Round(hours.Average(h => h.Chance_Of_Snow))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<(double Latitude, double Longitude, string name)?> GetCoordinatesAsync(string address)
|
||||||
|
{
|
||||||
|
using var client = new HttpClient();
|
||||||
|
|
||||||
|
client.DefaultRequestHeaders.Add("User-Agent", "dotnet-geocoder-app");
|
||||||
|
|
||||||
|
var url = $"https://nominatim.openstreetmap.org/search?q={Uri.EscapeDataString(address)}&format=json&limit=1";
|
||||||
|
|
||||||
|
var response = await client.GetAsync(url);
|
||||||
|
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var content = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
|
var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
|
||||||
|
var results = JsonSerializer.Deserialize<NominatimResult[]>(content, options);
|
||||||
|
|
||||||
|
if (!(results?.Length > 0))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var lat = double.Parse(results[0].Lat);
|
||||||
|
var lon = double.Parse(results[0].Lon);
|
||||||
|
var name = results[0].name;
|
||||||
|
return (lat, lon, name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class NominatimResult
|
||||||
|
{
|
||||||
|
public string Lat { get; set; }
|
||||||
|
public string Lon { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
23
HomeApi/Dockerfile
Normal file
23
HomeApi/Dockerfile
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
|
||||||
|
USER $APP_UID
|
||||||
|
WORKDIR /app
|
||||||
|
EXPOSE 8080
|
||||||
|
EXPOSE 8081
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
WORKDIR /src
|
||||||
|
COPY ["HomeApi/HomeApi.csproj", "HomeApi/"]
|
||||||
|
RUN dotnet restore "HomeApi/HomeApi.csproj"
|
||||||
|
COPY . .
|
||||||
|
WORKDIR "/src/HomeApi"
|
||||||
|
RUN dotnet build "./HomeApi.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||||
|
|
||||||
|
FROM build AS publish
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
RUN dotnet publish "./HomeApi.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||||
|
|
||||||
|
FROM base AS final
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=publish /app/publish .
|
||||||
|
ENTRYPOINT ["dotnet", "HomeApi.dll"]
|
||||||
21
HomeApi/HomeApi.csproj
Normal file
21
HomeApi/HomeApi.csproj
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.7"/>
|
||||||
|
<PackageReference Include="Scalar.AspNetCore" Version="2.5.6" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="..\.dockerignore">
|
||||||
|
<Link>.dockerignore</Link>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
6
HomeApi/HomeApi.http
Normal file
6
HomeApi/HomeApi.http
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
@HomeApi_HostAddress = http://localhost:5128
|
||||||
|
|
||||||
|
GET {{HomeApi_HostAddress}}/weatherforecast/
|
||||||
|
Accept: application/json
|
||||||
|
|
||||||
|
###
|
||||||
20
HomeApi/Models/ApiConfiguration.cs
Normal file
20
HomeApi/Models/ApiConfiguration.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
namespace HomeApi;
|
||||||
|
|
||||||
|
public class ApiConfiguration
|
||||||
|
{
|
||||||
|
public Keys Keys { get; set; } = new();
|
||||||
|
public BaseUrls BaseUrls { get; set; } = new();
|
||||||
|
public string DefaultCity { get; set; } = "Vega stockholms lan";
|
||||||
|
}
|
||||||
|
|
||||||
|
public class BaseUrls
|
||||||
|
{
|
||||||
|
public string Weather { get; set; } = string.Empty;
|
||||||
|
public string SL { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Keys
|
||||||
|
{
|
||||||
|
public string Weather { get; set; } = string.Empty;
|
||||||
|
public string SL { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
128
HomeApi/Models/AuroraForecast.cs
Normal file
128
HomeApi/Models/AuroraForecast.cs
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
namespace HomeApi.Models;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
public class AuroraForecast
|
||||||
|
{
|
||||||
|
[JsonPropertyName("date")]
|
||||||
|
public DateTime Date { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("ace")]
|
||||||
|
public AceData Ace { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("weather")]
|
||||||
|
public bool Weather { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("probability")]
|
||||||
|
public ProbabilityData Probability { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("message")]
|
||||||
|
public List<string> Message { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AceData
|
||||||
|
{
|
||||||
|
[JsonPropertyName("date")]
|
||||||
|
public DateTime Date { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("bz")]
|
||||||
|
public string Bz { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("density")]
|
||||||
|
public string Density { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("speed")]
|
||||||
|
public string Speed { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("kp1hour")]
|
||||||
|
public string Kp1Hour { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("kp4hour")]
|
||||||
|
public string Kp4Hour { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("kp")]
|
||||||
|
public string Kp { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("colour")]
|
||||||
|
public ColourData Colour { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ColourData
|
||||||
|
{
|
||||||
|
[JsonPropertyName("bz")]
|
||||||
|
public string Bz { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("density")]
|
||||||
|
public string Density { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("speed")]
|
||||||
|
public string Speed { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("kp1hour")]
|
||||||
|
public string Kp1Hour { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("kp4hour")]
|
||||||
|
public string Kp4Hour { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("kp")]
|
||||||
|
public string Kp { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ProbabilityData
|
||||||
|
{
|
||||||
|
[JsonPropertyName("date")]
|
||||||
|
public DateTime Date { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("calculated")]
|
||||||
|
public CalculatedProbability Calculated { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("colour")]
|
||||||
|
public string Colour { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("lat")]
|
||||||
|
public string Lat { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("long")]
|
||||||
|
public string Long { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("value")]
|
||||||
|
public int Value { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("highest")]
|
||||||
|
public HighestProbability Highest { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CalculatedProbability
|
||||||
|
{
|
||||||
|
[JsonPropertyName("lat")]
|
||||||
|
public double Lat { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("long")]
|
||||||
|
public double Long { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("value")]
|
||||||
|
public int Value { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("colour")]
|
||||||
|
public string Colour { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class HighestProbability
|
||||||
|
{
|
||||||
|
[JsonPropertyName("date")]
|
||||||
|
public DateTime Date { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("colour")]
|
||||||
|
public string Colour { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("lat")]
|
||||||
|
public double Lat { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("long")]
|
||||||
|
public double Long { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("value")]
|
||||||
|
public int Value { get; set; }
|
||||||
|
}
|
||||||
67
HomeApi/Models/Home.cs
Normal file
67
HomeApi/Models/Home.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
namespace HomeApi.Models;
|
||||||
|
|
||||||
|
public class Home
|
||||||
|
{
|
||||||
|
public string CityName { get; set; } = string.Empty;
|
||||||
|
public Current Current { get; set; } = new();
|
||||||
|
public List<Forecast> Forecast { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Current
|
||||||
|
{
|
||||||
|
public string Date { get; set; }
|
||||||
|
public double Feelslike { get; set; }
|
||||||
|
public int IsDay { get; set; }
|
||||||
|
public double WindPerHour { get; set; } = new();
|
||||||
|
public double WindGustPerHour { get; set; } = new();
|
||||||
|
public double Temperature { get; set; } = new();
|
||||||
|
public Probability AuroraProbability { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Probability
|
||||||
|
{
|
||||||
|
public DateTime Date { get; set; }
|
||||||
|
public CalculatedProbability Calculated { get; set; } // my location?
|
||||||
|
public string Colour { get; set; }
|
||||||
|
public int Value { get; set; }
|
||||||
|
public Highest HighestProbability { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Highest
|
||||||
|
{
|
||||||
|
public DateTime Date { get; set; }
|
||||||
|
public string Colour { get; set; }
|
||||||
|
public double Lat { get; set; }
|
||||||
|
public double Long { get; set; }
|
||||||
|
public int Value { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Forecast
|
||||||
|
{
|
||||||
|
public string Date { get; set; }
|
||||||
|
public double MinTempC { get; set; }
|
||||||
|
public double MaxTempC { get; set; }
|
||||||
|
public string DayIcon { get; set; }
|
||||||
|
public WeatherSummary Day { get; set; }
|
||||||
|
public WeatherSummary Night { get; set; }
|
||||||
|
public Astro Astro { get; set; }
|
||||||
|
}
|
||||||
|
public class Astro
|
||||||
|
{
|
||||||
|
public string Sunrise { get; set; }
|
||||||
|
public string Sunset { get; set; }
|
||||||
|
public string Moonrise { get; set; }
|
||||||
|
public string Moonset { get; set; }
|
||||||
|
public string Moon_Phase { get; set; }
|
||||||
|
public double? Moon_Illumination { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WeatherSummary
|
||||||
|
{
|
||||||
|
public string ConditionText { get; set; }
|
||||||
|
public string ConditionIcon { get; set; }
|
||||||
|
public double AvgTempC { get; set; }
|
||||||
|
public double AvgFeelslikeC { get; set; }
|
||||||
|
public int TotalChanceOfRain { get; set; }
|
||||||
|
public int TotalChanceOfSnow { get; set; }
|
||||||
|
}
|
||||||
172
HomeApi/Models/WeatherApiResponse.cs
Normal file
172
HomeApi/Models/WeatherApiResponse.cs
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
public class WeatherData
|
||||||
|
{
|
||||||
|
public Location Location { get; set; }
|
||||||
|
public Current Current { get; set; }
|
||||||
|
public Forecast Forecast { get; set; }
|
||||||
|
public Alerts Alerts { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Location
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Region { get; set; }
|
||||||
|
public string Country { get; set; }
|
||||||
|
public double Lat { get; set; }
|
||||||
|
public double Lon { get; set; }
|
||||||
|
public string Tz_Id { get; set; }
|
||||||
|
public long Localtime_Epoch { get; set; }
|
||||||
|
public string Localtime { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Current
|
||||||
|
{
|
||||||
|
public long Last_Updated_Epoch { get; set; }
|
||||||
|
public string Last_Updated { get; set; }
|
||||||
|
public double Temp_C { get; set; }
|
||||||
|
public double Temp_F { get; set; }
|
||||||
|
public int Is_Day { get; set; }
|
||||||
|
public Condition Condition { get; set; }
|
||||||
|
public double Wind_Mph { get; set; }
|
||||||
|
public double Wind_Kph { get; set; }
|
||||||
|
public int Wind_Degree { get; set; }
|
||||||
|
public string Wind_Dir { get; set; }
|
||||||
|
public double Pressure_Mb { get; set; }
|
||||||
|
public double Pressure_In { get; set; }
|
||||||
|
public double Precip_Mm { get; set; }
|
||||||
|
public double Precip_In { get; set; }
|
||||||
|
public int Humidity { get; set; }
|
||||||
|
public int Cloud { get; set; }
|
||||||
|
public double Feelslike_C { get; set; }
|
||||||
|
public double Feelslike_F { get; set; }
|
||||||
|
public double Vis_Km { get; set; }
|
||||||
|
public double Vis_Miles { get; set; }
|
||||||
|
public double Uv { get; set; } // changed to double
|
||||||
|
public double Gust_Mph { get; set; }
|
||||||
|
public double Gust_Kph { get; set; } // i byarna
|
||||||
|
public AirQuality Air_Quality { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Condition
|
||||||
|
{
|
||||||
|
public string Text { get; set; }
|
||||||
|
public string Icon { get; set; }
|
||||||
|
public int Code { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AirQuality
|
||||||
|
{
|
||||||
|
public double Co { get; set; }
|
||||||
|
public double No2 { get; set; }
|
||||||
|
public double O3 { get; set; }
|
||||||
|
public double So2 { get; set; }
|
||||||
|
public double Pm2_5 { get; set; }
|
||||||
|
public double Pm10 { get; set; }
|
||||||
|
public int Us_Epa_Index { get; set; }
|
||||||
|
public int Gb_Defra_Index { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Forecast
|
||||||
|
{
|
||||||
|
public List<ForecastDay> Forecastday { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ForecastDay
|
||||||
|
{
|
||||||
|
public string Date { get; set; }
|
||||||
|
public long Date_Epoch { get; set; }
|
||||||
|
public Day Day { get; set; }
|
||||||
|
public Astro Astro { get; set; }
|
||||||
|
public List<Hour> Hour { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Day
|
||||||
|
{
|
||||||
|
public double Maxtemp_C { get; set; }
|
||||||
|
public double Maxtemp_F { get; set; }
|
||||||
|
public double Mintemp_C { get; set; }
|
||||||
|
public double Mintemp_F { get; set; }
|
||||||
|
public double Avgtemp_C { get; set; }
|
||||||
|
public double Avgtemp_F { get; set; }
|
||||||
|
public double Maxwind_Mph { get; set; }
|
||||||
|
public double Maxwind_Kph { get; set; }
|
||||||
|
public double Totalprecip_Mm { get; set; }
|
||||||
|
public double Totalprecip_In { get; set; }
|
||||||
|
public double Avgvis_Km { get; set; }
|
||||||
|
public double Avgvis_Miles { get; set; }
|
||||||
|
public int Avghumidity { get; set; }
|
||||||
|
public int Daily_Will_It_Rain { get; set; }
|
||||||
|
public int Daily_Chance_Of_Rain { get; set; }
|
||||||
|
public int Daily_Will_It_Snow { get; set; }
|
||||||
|
public int Daily_Chance_Of_Snow { get; set; }
|
||||||
|
public Condition Condition { get; set; }
|
||||||
|
public double Uv { get; set; } // changed to double
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Astro
|
||||||
|
{
|
||||||
|
public string Sunrise { get; set; }
|
||||||
|
public string Sunset { get; set; }
|
||||||
|
public string Moonrise { get; set; }
|
||||||
|
public string Moonset { get; set; }
|
||||||
|
public string Moon_Phase { get; set; }
|
||||||
|
public double? Moon_Illumination { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Hour
|
||||||
|
{
|
||||||
|
public long Time_Epoch { get; set; }
|
||||||
|
public string Time { get; set; }
|
||||||
|
public double Temp_C { get; set; }
|
||||||
|
public double Temp_F { get; set; }
|
||||||
|
public int Is_Day { get; set; }
|
||||||
|
public Condition Condition { get; set; }
|
||||||
|
public double Wind_Mph { get; set; }
|
||||||
|
public double Wind_Kph { get; set; }
|
||||||
|
public int Wind_Degree { get; set; }
|
||||||
|
public string Wind_Dir { get; set; }
|
||||||
|
public double Pressure_Mb { get; set; }
|
||||||
|
public double Pressure_In { get; set; }
|
||||||
|
public double Precip_Mm { get; set; }
|
||||||
|
public double Precip_In { get; set; }
|
||||||
|
public int Humidity { get; set; }
|
||||||
|
public int Cloud { get; set; }
|
||||||
|
public double Feelslike_C { get; set; }
|
||||||
|
public double Feelslike_F { get; set; }
|
||||||
|
public double Windchill_C { get; set; }
|
||||||
|
public double Windchill_F { get; set; }
|
||||||
|
public double Heatindex_C { get; set; }
|
||||||
|
public double Heatindex_F { get; set; }
|
||||||
|
public double Dewpoint_C { get; set; }
|
||||||
|
public double Dewpoint_F { get; set; }
|
||||||
|
public int Will_It_Rain { get; set; }
|
||||||
|
public int Chance_Of_Rain { get; set; }
|
||||||
|
public int Will_It_Snow { get; set; }
|
||||||
|
public int Chance_Of_Snow { get; set; }
|
||||||
|
public double Vis_Km { get; set; }
|
||||||
|
public double Vis_Miles { get; set; }
|
||||||
|
public double Gust_Mph { get; set; }
|
||||||
|
public double Gust_Kph { get; set; }
|
||||||
|
public double Uv { get; set; } // changed to double
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Alerts
|
||||||
|
{
|
||||||
|
public List<Alert> Alert { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Alert
|
||||||
|
{
|
||||||
|
public string Headline { get; set; }
|
||||||
|
public string Msgtype { get; set; }
|
||||||
|
public string Severity { get; set; }
|
||||||
|
public string Urgency { get; set; }
|
||||||
|
public string Areas { get; set; }
|
||||||
|
public string Category { get; set; }
|
||||||
|
public string Certainty { get; set; }
|
||||||
|
public string Event { get; set; }
|
||||||
|
public string Note { get; set; }
|
||||||
|
public string Effective { get; set; }
|
||||||
|
public string Expires { get; set; }
|
||||||
|
public string Desc { get; set; }
|
||||||
|
public string Instruction { get; set; }
|
||||||
|
}
|
||||||
27
HomeApi/Program.cs
Normal file
27
HomeApi/Program.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using HomeApi;
|
||||||
|
using Scalar.AspNetCore;
|
||||||
|
|
||||||
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
// Add services to the container.
|
||||||
|
builder.Services.AddHttpClient();
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||||
|
builder.Services.AddOpenApi();
|
||||||
|
builder.Services.Configure<ApiConfiguration>(builder.Configuration.GetSection("ApiConfiguration"));
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
|
// Configure the HTTP request pipeline.
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.MapOpenApi();
|
||||||
|
app.MapScalarApiReference();
|
||||||
|
}
|
||||||
|
|
||||||
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
app.MapControllers();
|
||||||
|
|
||||||
|
app.Run();
|
||||||
23
HomeApi/Properties/launchSettings.json
Normal file
23
HomeApi/Properties/launchSettings.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||||
|
"profiles": {
|
||||||
|
"http": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": false,
|
||||||
|
"applicationUrl": "http://localhost:5128",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"https": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": false,
|
||||||
|
"applicationUrl": "https://localhost:7162;http://localhost:5128",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
19
HomeApi/appsettings.Development.json
Normal file
19
HomeApi/appsettings.Development.json
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ApiConfiguration": {
|
||||||
|
"Keys": {
|
||||||
|
"Weather": "KEY",
|
||||||
|
"SL": ""
|
||||||
|
},
|
||||||
|
"BaseUrls": {
|
||||||
|
"Weather": "https://api.weatherapi.com/v1",
|
||||||
|
"SL": "NOT CONFIGURED"
|
||||||
|
},
|
||||||
|
"DefaultCity": "Vega stockholms lan"
|
||||||
|
},
|
||||||
|
}
|
||||||
20
HomeApi/appsettings.json
Normal file
20
HomeApi/appsettings.json
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ApiConfiguration": {
|
||||||
|
"Keys": {
|
||||||
|
"Weather": "KEY",
|
||||||
|
"SL": ""
|
||||||
|
},
|
||||||
|
"BaseUrls": {
|
||||||
|
"Weather": "https://api.weatherapi.com/v1",
|
||||||
|
"SL": "NOT CONFIGURED"
|
||||||
|
},
|
||||||
|
"DefaultCity": "Vega stockholms lan"
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*"
|
||||||
|
}
|
||||||
3
Program.cs
Normal file
3
Program.cs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
|
||||||
|
Console.WriteLine("Hello, World!");
|
||||||
13
compose.yaml
Normal file
13
compose.yaml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
services:
|
||||||
|
homeapi:
|
||||||
|
image: homeapi
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
|
||||||
|
homeapi-1:
|
||||||
|
image: homeapi-1
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: HomeApi/Dockerfile
|
||||||
|
|
||||||
Reference in New Issue
Block a user