Skip to content

Commit c536692

Browse files
committed
Merge branch 'release/v1.1'
2 parents deb9fc9 + fa8e83c commit c536692

8 files changed

Lines changed: 25 additions & 14 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ riderModule.iml
55
/_ReSharper.Caches/
66
.idea/.idea.console-weather/.idea/
77
console-weather/config.json
8+
9+
console-weather/nupkg/

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ The key is kept in `C:\Users\USERNAME\Documents\weather_data`
3232
## Usage
3333
To use application, just simply type:
3434
```bash
35+
weather
36+
```
37+
To get weather info from a specified city, type:
38+
```bash
3539
weather -c "City Name"
3640
```
3741

@@ -59,7 +63,7 @@ Weather Alerts:
5963
```
6064
## Acknowledgements
6165

62-
- [NuGet Package page](https://www.nuget.org/packages/console-weather/)
66+
- [NuGet Page](https://www.nuget.org/packages/console-weather/)
6367

6468

6569
## License and support
@@ -71,3 +75,4 @@ For any project-related cases, please contact me on Discord: pazurkota#1001
7175
## Lessons Learned
7276

7377
This project basically was created to learn how to work with the API (in this case, weather API) and creating CLI apps using C#
78+

console-weather/API/ApiData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ private string GetRequest() {
2020
try {
2121
// Get API Key if invalid or not given
2222
while (!CheckApiKeyValidity(apiKey)) {
23-
apiKey = SetApiKey();
23+
SetApiKey();
2424
}
2525

2626
// Client options

console-weather/API/ApiKeyHandler.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class ApiKeyHandler {
2121
}
2222

2323
// Set API Key
24-
public static string? SetApiKey() {
24+
public static void SetApiKey() {
2525
string filePath = CONFIGPATH;
2626

2727
Console.Write("\nYour API Key is invalid or missing." +
@@ -35,7 +35,5 @@ public class ApiKeyHandler {
3535
config["api-key"] = apiKey;
3636

3737
File.WriteAllText(filePath, config.ToString());
38-
39-
return GetApiKey();
4038
}
4139
}

console-weather/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public static async Task<int> Main(string[] args) {
2626
}
2727

2828
private static void OnHandle(string str) {
29+
// Get city name from IP address if city name not provided
30+
str ??= "auto:ip";
31+
2932
ApiData.CITYNAME = str;
3033
ApiData data = new ApiData();
3134

console-weather/Weather/Weather.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class Weather {
99
public override string ToString() {
1010
string str = $"Weather for {Location.Name}, {Location.Country} (last update: {Current.LastUpdated}):";
1111

12-
str += $"\n\nTeperature: {Current.Temperature}°C (feels like: {Current.FeelsLikeTemp}°C)";
12+
str += $"\n\nTemperature: {Current.Temperature}°C (feels like: {Current.FeelsLikeTemp}°C)";
1313
str += $"\nWeather Condition: {Current.Condition.ConditionState}";
1414
str += $"\nWind Speed: {Current.WindSpeed}kmp ({Current.WindDirection})";
1515
str += $"\nAir Pressure: {Current.Pressure} mbar";
@@ -21,14 +21,16 @@ public override string ToString() {
2121
}
2222

2323
private string ShowWeatherAlerts() {
24-
string str = "";
24+
// Return "<none>" if no alerts issued
25+
if (Alerts.WeatherAlerts.Count == 0) {
26+
return "<none>";
27+
}
2528

26-
if (Alerts.WeatherAlerts.Count > 0) {
27-
foreach (var alert in Alerts.WeatherAlerts) {
28-
str += $"{alert.AlertEvent} issued by {alert.AlertHeadline}:\n{alert.AlertDescription}\n\n";
29-
}
29+
string str = "";
30+
31+
foreach (var alert in Alerts.WeatherAlerts) {
32+
str += $"{alert.AlertEvent} issued by {alert.AlertHeadline}:\n{alert.AlertDescription}\n\n";
3033
}
31-
else str = "<none>";
3234

3335
return str;
3436
}

console-weather/console-weather.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +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.0</PackageVersion>
18+
<PackageVersion>1.1</PackageVersion>
19+
<VersionPrefix>1.1</VersionPrefix>
1920
<Title>Console Weather</Title>
2021
<Copyright>Copyright (c) 2023 pazurk0ta</Copyright>
2122
<RepositoryUrl>https://github.com/pazurkota/console-weather</RepositoryUrl>
2223
<RepositoryType>git</RepositoryType>
23-
<PackageReleaseNotes>Initial Release</PackageReleaseNotes>
24+
<PackageReleaseNotes>Added auto-city lookup via IP</PackageReleaseNotes>
2425
</PropertyGroup>
2526

2627
<ItemGroup>
-784 KB
Binary file not shown.

0 commit comments

Comments
 (0)