Skip to content

Commit

Permalink
imp - doc - Prepare the TWC weather forecast info
Browse files Browse the repository at this point in the history
---

We need to make room for the new temperature querying system that uses TWC.

---

Type: imp
Breaking: False
Doc Required: True
Part: 1/1
  • Loading branch information
AptiviCEO committed Jun 7, 2024
1 parent 4a94cb9 commit 44e4cea
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,21 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using System;
using System.Linq;
using Nettify.Weather;
using Nitrocid.ConsoleBase.Colors;
using Nitrocid.ConsoleBase.Writers;
using Terminaux.Writer.ConsoleWriters;
using Nitrocid.Languages;
using Nitrocid.Shell.ShellBase.Commands;
using Nitrocid.ConsoleBase.Inputs;

namespace Nitrocid.Extras.Forecast.Forecast.Commands
{
/// <summary>
/// Shows weather information for a specified city
/// </summary>
/// <remarks>
/// We credit OpenWeatherMap for their decent free API service for weather information for the cities around the world. It requires that you have your own API key for OpenWeatherMap. Don't worry, Nitrocid KS only accesses free features; all you have to do is make an account and generate your own API key.
/// We credit IBM for their decent API service for weather information for the cities around the world from The Weather Channel.
/// <br></br>
/// This command lets you get current weather information for a specified city by city ID as recommended by OpenWeatherMap. If you want a list, use the switch indicated below.
/// This command lets you get current weather information for a specified city by city ID from The Weather Channel servers. If you want a list, use the switch indicated below.
/// <br></br>
/// <list type="table">
/// <listheader>
Expand All @@ -44,7 +40,7 @@ namespace Nitrocid.Extras.Forecast.Forecast.Commands
/// </listheader>
/// <item>
/// <term>-list</term>
/// <description>Lists the available cities</description>
/// <description>Searches for the written city name and returns the list of longitudes and latitudes</description>
/// </item>
/// </list>
/// <br></br>
Expand All @@ -54,30 +50,7 @@ class WeatherCommand : BaseCommand, ICommand

public override int Execute(CommandParameters parameters, ref string variableValue)
{
var ListMode = false;
if (parameters.SwitchesList.Contains("-list"))
ListMode = true;
if (ListMode)
{
var Cities = WeatherForecast.ListAllCities();
ListWriterColor.WriteList(Cities);
}
else
{
string APIKey = Forecast.ApiKey;
if (parameters.ArgumentsList.Length > 1)
{
APIKey = parameters.ArgumentsList[1];
}
else if (string.IsNullOrEmpty(APIKey))
{
TextWriterColor.Write(Translate.DoTranslation("You can get your own API key at https://home.openweathermap.org/api_keys."));
TextWriters.Write(Translate.DoTranslation("Enter your API key:") + " ", false, KernelColorType.Input);
APIKey = InputTools.ReadLineNoInput();
Forecast.ApiKey = APIKey;
}
Forecast.PrintWeatherInfo(parameters.ArgumentsList[0], APIKey);
}
TextWriters.Write("Coming soon...", KernelColorType.NeutralText);
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//
// Nitrocid KS Copyright (C) 2018-2024 Aptivi
//
// This file is part of Nitrocid KS
//
// Nitrocid KS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Nitrocid KS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using System;
using System.Linq;
using Nettify.Weather;
using Nitrocid.ConsoleBase.Colors;
using Nitrocid.ConsoleBase.Writers;
using Terminaux.Writer.ConsoleWriters;
using Nitrocid.Languages;
using Nitrocid.Shell.ShellBase.Commands;
using Nitrocid.ConsoleBase.Inputs;

namespace Nitrocid.Extras.Forecast.Forecast.Commands
{
/// <summary>
/// Shows weather information for a specified city
/// </summary>
/// <remarks>
/// We credit OpenWeatherMap for their decent free API service for weather information for the cities around the world. It requires that you have your own API key for OpenWeatherMap. Don't worry, Nitrocid KS only accesses free features; all you have to do is make an account and generate your own API key.
/// <br></br>
/// This command lets you get current weather information for a specified city by city ID as recommended by OpenWeatherMap. If you want a list, use the switch indicated below.
/// <br></br>
/// <list type="table">
/// <listheader>
/// <term>Switches</term>
/// <description>Description</description>
/// </listheader>
/// <item>
/// <term>-list</term>
/// <description>Lists the available cities</description>
/// </item>
/// </list>
/// <br></br>
/// </remarks>
class WeatherOldCommand : BaseCommand, ICommand
{

public override int Execute(CommandParameters parameters, ref string variableValue)
{
var ListMode = false;
if (parameters.SwitchesList.Contains("-list"))
ListMode = true;
if (ListMode)
{
var Cities = WeatherForecast.ListAllCities();
ListWriterColor.WriteList(Cities);
}
else
{
string APIKey = Forecast.ApiKey;
if (parameters.ArgumentsList.Length > 1)
{
APIKey = parameters.ArgumentsList[1];
}
else if (string.IsNullOrEmpty(APIKey))
{
TextWriterColor.Write(Translate.DoTranslation("You can get your own API key at https://home.openweathermap.org/api_keys."));
TextWriters.Write(Translate.DoTranslation("Enter your API key:") + " ", false, KernelColorType.Input);
APIKey = InputTools.ReadLineNoInput();
Forecast.ApiKey = APIKey;
}
Forecast.PrintWeatherInfo(parameters.ArgumentsList[0], APIKey);
}
return 0;
}

public override void HelpHelper()
{
TextWriterColor.Write(Translate.DoTranslation("You can either consult the below link for the list of cities with their IDs, or, pass \"-list\" to this command."));
TextWriterColor.Write("http://bulk.openweathermap.org/sample/city.list.json.gz");
}

}
}
21 changes: 19 additions & 2 deletions public/Nitrocid.Addons/Nitrocid.Extras.Forecast/ForecastInit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,24 @@ internal class ForecastInit : IAddon
{
private readonly List<CommandInfo> addonCommands =
[
new CommandInfo("weather", /* Localizable */ "Shows weather info for specified city. Uses OpenWeatherMap.",
new CommandInfo("weather", /* Localizable */ "Shows weather info for specified city. Uses The Weather Channel from IBM.",
[
new CommandArgumentInfo(
[
new CommandArgumentPart(true, "latitude"),
new CommandArgumentPart(true, "longitude"),
new CommandArgumentPart(false, "apikey"),
],
[
new SwitchInfo("list", /* Localizable */ "Shows all the available cities and their latitude/longitude pairs", new SwitchOptions()
{
OptionalizeLastRequiredArguments = 3,
AcceptsValues = true,
ArgumentsRequired = true,
})
])
], new WeatherCommand()),
new CommandInfo("weather-old", /* Localizable */ "Shows weather info for specified city. Uses OpenWeatherMap.",
[
new CommandArgumentInfo(
[
Expand All @@ -52,7 +69,7 @@ internal class ForecastInit : IAddon
AcceptsValues = false
})
])
], new WeatherCommand())
], new WeatherOldCommand()),
];

string IAddon.AddonName =>
Expand Down

0 comments on commit 44e4cea

Please sign in to comment.