Skip to content

Instantly share code, notes, and snippets.

@flyinva
Last active August 29, 2015 14:23
Show Gist options
  • Save flyinva/e40c3f8fd6c9e8e43774 to your computer and use it in GitHub Desktop.
Save flyinva/e40c3f8fd6c9e8e43774 to your computer and use it in GitHub Desktop.
Get weather condition from http://openweathermap.org
#!/bin/bash
city="$1"
curl --silent "http://api.openweathermap.org/data/2.5/weather?q=$city&units=metric" \
| jq --argfile wind ~/.config/wind.json \
'{"city": .name, "updated": .dt, "sunrise": .sys.sunrise, "sunset":.sys.sunset, "temperature": .main.temp, "wind": {"speed": (.wind.speed*3.6|floor), "direction": $wind[((.wind.deg+11.25)/22.5)|floor]}}' \
| sed -r 's/(.*:) ([0-9]{10,}),/echo -n "\1: " ; date "+%Y-%m-%d %H:%M:%S" -d"@\2"/e' \
> $city.json
# vim: ts=2 sw=2 sts=2 sr noet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment