Skip to content

Instantly share code, notes, and snippets.

@CrazyLemon
Created January 6, 2016 14:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CrazyLemon/dd65100c0eb7dfec2edb to your computer and use it in GitHub Desktop.
Save CrazyLemon/dd65100c0eb7dfec2edb to your computer and use it in GitHub Desktop.
current weather for Kranj
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# RPi_SmartWatch_MAX7219
# Created by Jonatas Freitas - https://github.com/jonatasfreitasv
# https://github.com/jonatasfreitasv/RPi_SmartWatch_MAX7219
#
import datetime, time, urllib, json
# OpenWeather
weather_city = "Kranj"
weather_key = "2de143494c0b295cca9337e1e96b00e0"
weather_url = ("http://api.openweathermap.org/data/2.5/weather?q=%s&units=metric&appid=%s") % (weather_city, weather_key)
# Get weather data
weather_data = urllib.urlopen(weather_url)
weather_json = json.loads(weather_data.read())
# Variables
degrees = u"\N{DEGREE SIGN}"
city = weather_json["name"]
temp = "%s%sC" % (weather_json["main"]["temp"], degrees)
#cloudness = "Clouds:%s%%" % str(weather_json["clouds"]["all"])
weather = "%s, %s" % (weather_json["weather"][0]["description"], weather_json["weather"][1]["description"])
humidity = "%s%%" % str(weather_json["main"]["humidity"])
time = "-%s-" % str(datetime.datetime.now().strftime("%H:%M"))
pressure = "%s hPa" % weather_json["main"]["pressure"]
wind = "%s m/s" % weather_json["wind"]["speed"]
print("%s: %s %s" % (city, temp, weather))
print("Pritisk: %s Vlaznost: %s Veter: %s" % (pressure, humidity, wind))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment