Utility made for easy and fast yield of weather report for the area.
It uses a fantastic website called wttr.in for the weather report itself
A JSON library is made by @nlohmann!
The program is based off a python script by @SolDoesTech, SolDoesTech/HyprV/waybar/scripts/waybar-wttr.py
This small program is made for people who want to check the weather, above all things. This might include checking the weather by displaying it in the Waybar or anything like that, too!
Website looks at your IP for the area you're located at. Using proxy or VPN will most likely yield incorrect results unless you specify location as an argument. For instruction look at the Usage section.
- Using your package manager install curl developer package.
- Ubuntu:
sudo apt-get install libcurl4-openssl-dev
- Arch:
sudo pacman -S curl
- Ubuntu:
- Clone the repository using
git clone https://github.com/alexlnkp/weatherscript.git
cd
into the cloned repository'- Make
-
Run
make SYSTEM=imperial
for Imperial system (Fahrenheit)OR
-
Run
make SYSTEM=metric
or simplymake
for Metric system (Celcius)
-
- To get a weather forecast for the area determined by your IP - simply run the program.
- To get a weather forecast for a specific area - run the program with an argument (e.g.
Paris
for weather in Paris)
The code relies on simply requesting the webpage's contents directly from https://wttr.in/?format=j1.
It yields the JSON table that includes a TON of information about the weather, including FeelsLike[C|F]
, visibility[Miles]
, humidity
, and much more!
Therefore, you can very simply modify the code by adding or removing data you parse from the JSON.
For instance, here's how you yield the visibility
in meters:
src/main.cpp
:
std::string visibility = json_res["current_condition"][0]["visibility"];
Then, you can easily modify the std::cout
by adding this information. For example:
src/main.cpp
:
std::cout << weather_symbol << ' ' << temp << TEMP_SYMBOL << '(' << visibility << ')' << std::endl;
Will print out additionally the Visibility parameter for the temperature in the parenthesis.
You could also make code more versatile by looking at the top of the main.cpp
and changing the fields to yield information from according to the system the app is built for.
So, you could add a new define at the top, like so:
src/main.cpp
:
#ifdef IMPERIAL
#define TEMP_SYMBOL "°F"
#define TEMP_TYPE "temp_F"
#define VISIBILITY "visibilityMiles" // Our new data
#else
#define TEMP_SYMBOL "°C"
#define TEMP_TYPE "temp_C"
#define VISIBILITY "visibility" // Our new data
#endif
This way, the data to yield is decided at the compile time by the SYSTEM
variable you pass to make
.
If you make with SYSTEM=imperial
- the information you yield will be in an imperial system.
In other words, you will yield visibilityMiles
data instead of visibility
(meters).