Code Monkey home page Code Monkey logo

wxo's Introduction

wxo

wxo is primarily a command line utility for retrieving "real-time-ish" current weather conditions for a given location.

The default output to stdout is formatted for use in minimalist window manager status bars such as dwmblocks or Goblocks on dwm. All output is text (UTF-8 text); there are no icons or colours to make your minimalist life cluttered.

Results are cached and expire by default in 5-10 minutes; expiry depends on the wx data provider's daily usage limits.

Installation & Usage

Get the latest:

go install github.com/solutionroute/wxo/cmd/wxo@latest

Using wxo with OpenWeathermap.org requires a free account and API key.

Run wxo for a usage screen. Note: You must provide the WXO_APIKEY environment variable, either on the command line, or as part of your permanent environment. Example:

$ WXO_APIKEY=yoursecretkey wxo -lat 49.123 -long -123.78

in use on dwm with Goblocks My dwm config feeding wxo output to Goblocks status bar

Example output without a weather alert:

Overcast Clouds 2.5C ↖NNW 3.2km/h

Some weather alerts:

!Extreme Cold! Clear Sky -27.9C ↖WNW 29.6km/h
!Flood Advisory! Overcast Clouds 40.3F ←W 3.6mph

Multiple alerts are concatenated and may be truncated (...):

!Moderate Rain-Flood Warning/Moderate Coa...! Overcast Clouds 10.5C ↗ENE 5.3km/h

Limited internationalization is available and is weather data provider dependent. Alert text may not be available in other languages.

# Vielha, Spain
#  wxo -lat 42.701287 -long 0.793591
en: !Moderate Wind Warning/Moderate Avalanche...! Overcast Clouds 4.7C ↑N 12.3km/h
#  wxo -lat 42.701287 -long 0.793591 -lang es
es: !Moderate Wind Warning/Moderate Avalanche...! Nubes 4.7C ↑N 12.3km

As a library

While it wasn't written for the purpose, the package could be used as a library for accessing various weather data sources. The wxo cmd main.go provides an example:

client := owm.NewWeatherClient(apiKey, latitude, longitude, units, lang)
wx, err := client.Fetch() // returns a SiteData object

Weather Sources

Currently wxo supports:

  • OpenWeathermap.org via their "One Call" API; you'll need a free API key. The free tier provides 1,000 "One Call" requests a day.

Motivation

As a distance runner, weather is important to me! As a weather geek, I don't need an excuse. I want to see seeing current temp, winds, and alerts on my dwm status bar; here's a relevant excerpt from my Goblocks config file:

"actions":
[
    {
        "prefix": "",
        "updateSignal": "36",
        "command": "WXO_APIKEY=myOWMkey /home/mw/go/bin/wxo -lat 49.2605 -long -123.1133 -units metric",
        "suffix": "",
        "timer": "10m"
    },
    ...
]

A hot-key issuing a shell command kill -36 $(pidof goblocks), causes goblocks to run the weather "block" and update the weather status line, subject to the default cache expiry (5 minutes).

Other Solutions:

  • wttr.in is used by many for status bar updates via curl, but I found the data returned was often partially incorrect (wind info in particular) or quite out of date, in addition to lacking weather alert data.

TODO

wxo was born on January 8th, 2022, and will continue to evolve with a few more features--in rough order of priority:

  • Cache output
  • Specify cache expiry, subject to weather data provider daily limits
  • Custom output templates
  • Other weather data providers

wxo's People

Watchers

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