Git Product home page Git Product logo

weatherscript's Introduction

C/C++ CI

WeatherScript - utility made for easy and fast yield of weather report for the area

It's using 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

Note

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.

Dependencies

  • Using your package manager install curl developer package.
    • Ubuntu: sudo apt-get install libcurl4-openssl-dev
    • Arch: sudo pacman -S curl

Building

  1. Clone the repository using git clone https://github.com/alexlnkp/weatherscript.git
  2. cd into the cloned repository'
  3. Make
    • Run make SYSTEM=imperial for Imperial system (Fahrenheit)

      OR

    • Run make SYSTEM=metric or simply make for Metric system (Celcius)

Usage

  • 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)

Modifying

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).

weatherscript's People

Contributors

alexlnkp avatar

Stargazers

Marouane El Hizabri avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.