Skip to content

Commit 1a8946e

Browse files
author
unknown
committed
Merge branch 'release/v1.7'
2 parents 6841707 + 454d851 commit 1a8946e

5 files changed

Lines changed: 112 additions & 18 deletions

File tree

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ $ dotnet tool update --global console-weather
3636
```
3737
## Usage
3838

39+
### Commands:
3940
```console
4041
# To use aplication, type:
4142
$ weather
@@ -59,6 +60,34 @@ $ weather -a
5960
$ weather --dont-show-icons
6061
```
6162

63+
### Default settings:
64+
This project uses default settings that are stored in `config.json` file. You can change them by editing this file:
65+
```json
66+
{
67+
"api-key": "api-key",
68+
"default-city": "Sydney",
69+
"dont-show-alerts": false,
70+
"show-forecast": false,
71+
"units": "EU",
72+
"air-quality": true,
73+
"dont-show-icons": false
74+
}
75+
```
76+
77+
- `"default-city"` - default city that will be used if you don't specify it in command
78+
- `"dont-show-alerts"` - if set to `true`, weather alerts won't be shown
79+
- `"show-forecast"` - if set to `true`, weather forecast will be shown
80+
- `"units"` - units that will be used to show weather data. Possible values: `eu`, `si`, `us`, `uk`
81+
- `"air-quality"` - if set to `true`, air quality data will be shown
82+
- `"dont-show-icons"` - if set to `true`, weather icons won't be shown
83+
84+
> **Note**: These settings is not required. You can use application without them.
85+
86+
The config file is kept in:
87+
- Windows: `C:\Users\USERNAME\Documents\weather_data\config.json`
88+
- MacOS: `/Users/USERNAME/Documents/weather_data/config.json`
89+
- Linux: `/home/USERNAME/Documents/weather_data/config.json`
90+
6291

6392
## Demo
6493
```console

console-weather/Program.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,31 @@ public static async Task<int> Main(string[] args) {
1616

1717
var alertsOption = new Option<bool>(
1818
"--no-alerts",
19-
() => false,
19+
DefaultSettings.DontShowAlerts,
2020
"Hide weather alerts"
2121
);
2222

2323
var forecastOption = new Option<bool>(
2424
new []{"--forecast", "-f"},
25-
() => false,
25+
DefaultSettings.ShowForecast,
2626
"Show weather forecast"
2727
);
2828

2929
var unitsOption = new Option<Units.UnitType>(
3030
new []{"--units", "-u"},
31-
() => Units.UnitType.Eu,
31+
DefaultSettings.GetUnitType,
3232
"Set weather units"
3333
);
3434

3535
var airQualityOption = new Option<bool>(
3636
new []{"--air-quality", "-a"},
37-
() => false,
37+
DefaultSettings.GetAirQuality,
3838
"Show air quality"
3939
);
40-
40+
4141
var iconsOption = new Option<bool>(
42-
new []{"--dont-show-icons"},
43-
() => false,
42+
new[] { "--dont-show-icons" },
43+
DefaultSettings.DontShowIcons,
4444
"Disable weather icons"
4545
);
4646

@@ -62,7 +62,7 @@ public static async Task<int> Main(string[] args) {
6262
}
6363

6464
private static void OnHandle(string cityName, bool showAlerts, bool showForecast, Units.UnitType units, bool airQuality, bool showIcons) {
65-
CityName = cityName ?? "auto:ip";
65+
CityName = cityName ?? DefaultSettings.GetCityName();
6666
DontShowAlerts = showAlerts;
6767
ShowForecast = showForecast;
6868
Settings.Units = units;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using Newtonsoft.Json.Linq;
2+
using console_weather.API;
3+
4+
namespace console_weather.Utility;
5+
6+
public class DefaultSettings {
7+
private static string GetJsonContent() {
8+
string filePath = JsonHandler.Configpath;
9+
10+
if (!File.Exists(filePath)) {
11+
JsonHandler.CreateConfigJsonFile();
12+
}
13+
14+
string jsonText = File.ReadAllText(filePath);
15+
return jsonText;
16+
}
17+
18+
public static bool DontShowAlerts() {
19+
JObject jObject = JObject.Parse(GetJsonContent());
20+
bool dontShowAlerts = jObject["dont-show-alerts"]?.ToObject<bool>() ?? false;
21+
22+
return dontShowAlerts;
23+
}
24+
25+
public static bool ShowForecast() {
26+
JObject jObject = JObject.Parse(GetJsonContent());
27+
bool showForecast = jObject["show-forecast"]?.ToObject<bool>() ?? false;
28+
29+
return showForecast;
30+
}
31+
32+
public static Units.UnitType GetUnitType() {
33+
JObject jObject = JObject.Parse(GetJsonContent());
34+
string unitType = jObject["units"]?.ToObject<string>()?.ToLower() ?? "eu";
35+
36+
return unitType switch {
37+
"eu" => Units.UnitType.Eu,
38+
"us" => Units.UnitType.Us,
39+
"si" => Units.UnitType.Si,
40+
"uk" => Units.UnitType.Uk,
41+
_ => Units.UnitType.Eu
42+
};
43+
}
44+
45+
public static bool GetAirQuality() {
46+
JObject jObject = JObject.Parse(GetJsonContent());
47+
bool airQuality = jObject["air-quality"]?.ToObject<bool>() ?? false;
48+
49+
return airQuality;
50+
}
51+
52+
public static bool DontShowIcons() {
53+
JObject jObject = JObject.Parse(GetJsonContent());
54+
bool dontShowIcons = jObject["dont-show-icons"]?.ToObject<bool>() ?? false;
55+
56+
return dontShowIcons;
57+
}
58+
59+
public static string GetCityName() {
60+
JObject jObject = JObject.Parse(GetJsonContent());
61+
string cityName = jObject["default-city"]?.ToObject<string>() ?? "auto:ip";
62+
63+
return cityName;
64+
}
65+
}

console-weather/Utility/PrintData.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ public static string Print() {
2020
str += $"Current Precipitation: {ShowPrecipitation()}\n";
2121
str += $"Current Humidity: {Data.Current.Humidity}%\n";
2222
str += $"Current Cloud Cover: {Data.Current.Cloud}%\n";
23-
str += $"Current UV Index: {Data.Current.UvIndex} ({ShowUvIndex()})";
23+
str += $"Current UV Index: {Data.Current.UvIndex} ({ShowUvIndex()})\n\n";
2424
str += ShowAlerts();
2525
str += ShowForecast();
2626
str += ShowAirQuality();
27-
str += $"\n\nLast Update: {Data.Current.LastUpdated}";
27+
str += $"Last Update: {Data.Current.LastUpdated}";
2828

2929
return str;
3030
}
@@ -41,7 +41,7 @@ private static string ShowAlerts() {
4141
return "";
4242
}
4343

44-
return alerts.WeatherAlerts.Aggregate("\n\nALERTS:\n", (current, alert) => current + $"{alert.AlertHeadline}:\n{alert.AlertDescription}\n\n");
44+
return alerts.WeatherAlerts.Aggregate("ALERTS:\n", (current, alert) => current + $"{alert.AlertHeadline}:\n{alert.AlertDescription}\n\n");
4545
}
4646

4747
private static string ShowForecast() {
@@ -53,14 +53,14 @@ private static string ShowForecast() {
5353

5454
var forecast = Data.Forecast.ForecastsDay[1].Day;
5555

56-
str += "\n\nFORECAST:";
56+
str += "FORECAST:";
5757
str += $"\nTomorrow it will be {forecast.Condition.ConditionState}";
5858
str += $"{ShowForecastTemp()}";
5959
str += $"\nMaximum Wind Speed: {ShowForecastWindSpeed()}";
6060
str += $"\nAverage Visibility: {ShowForecastVisibility()}";
6161
str += $"\nMaximum Precipitation: {ShowForecastPrecipitation()}";
6262
str += $"\nUV Index: {forecast.UvIndex} ({ShowForecastUvIndex()})";
63-
str += $"\nChance of rain/snow: {forecast.ChanceOfRain}% / {forecast.ChanceOfSnow}%";
63+
str += $"\nChance of rain/snow: {forecast.ChanceOfRain}% / {forecast.ChanceOfSnow}%\n\n";
6464

6565
return str;
6666
}
@@ -135,14 +135,14 @@ private static string ShowAirQuality() {
135135

136136
string str = "";
137137

138-
str += "\n\nAIR QUALITY:\n";
138+
str += "AIR QUALITY:\n";
139139
str += $"Carbon Monoxide: {Math.Round(airQuality.Co, 2)} μg/m³\n";
140140
str += $"Nitrogen Dioxide: {Math.Round(airQuality.No2, 2)} μg/m³\n";
141141
str += $"Ozone: {Math.Round(airQuality.O3, 2)} μg/m³\n";
142142
str += $"Sulphur Dioxide: {Math.Round(airQuality.So2, 2)} μg/m³\n";
143143
str += $"Fine Particles Matter: {Math.Round(airQuality.Pm25, 2)} μg/m³\n";
144144
str += $"Coarse Particles Matter: {Math.Round(airQuality.Pm10, 2)} μg/m³\n";
145-
str += $"US Epa Index: {airQuality.UsEpaIndex} ({PrintEpaStandards(airQuality.UsEpaIndex)})";
145+
str += $"US Epa Index: {airQuality.UsEpaIndex} ({PrintEpaStandards(airQuality.UsEpaIndex)})\n\n";
146146

147147
return str;
148148
}

console-weather/console-weather.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1616
<PackageProjectUrl>https://github.com/pazurkota/console-weather</PackageProjectUrl>
1717
<Description>Simple CLI App to check weather in C#</Description>
18-
<PackageVersion>1.6.1</PackageVersion>
19-
<VersionPrefix>1.6.1</VersionPrefix>
18+
<PackageVersion>1.7</PackageVersion>
19+
<VersionPrefix>1.7</VersionPrefix>
2020
<Title>Console Weather</Title>
2121
<Copyright>Copyright (c) 2023 pazurk0ta</Copyright>
2222
<RepositoryUrl>https://github.com/pazurkota/console-weather</RepositoryUrl>
2323
<RepositoryType>git</RepositoryType>
24-
<PackageReleaseNotes>Added weather icons and --dont-show-icons argument</PackageReleaseNotes>
24+
<PackageReleaseNotes>Added default setting</PackageReleaseNotes>
2525
</PropertyGroup>
2626

2727
<ItemGroup>

0 commit comments

Comments
 (0)