Skip to content

Instantly share code, notes, and snippets.

@whoizit
Last active August 14, 2019 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whoizit/2707bfae72b85dcfc8676abda515c140 to your computer and use it in GitHub Desktop.
Save whoizit/2707bfae72b85dcfc8676abda515c140 to your computer and use it in GitHub Desktop.
18°(18°) broken clouds, 4m/s, 63%, {}, 756mmHg
#!/usr/bin/env python3
# pip install --user -U python-dotenv pyowm meteocalc
# get API key in https://openweathermap.org
# create file .env
# OWM_API_KEY=1a1a1a1a1a1a1a1a1
# OWM_PLACE='Saint Petersburg,RU'
# https://github.com/theskumar/python-dotenv
# https://github.com/csparpa/pyowm
# https://github.com/malexer/meteocalc
import os
import meteocalc as mc
import pyowm
from dotenv import load_dotenv
load_dotenv()
owm = pyowm.OWM(os.getenv('OWM_API_KEY'))
observation = owm.weather_at_place(os.getenv('OWM_PLACE'))
w = observation.get_weather()
temp = mc.Temp(w.get_temperature('celsius')['temp'], 'c')
wind_speed = w.get_wind()['speed']
humidity = w.get_humidity()
# m/s to mph
to_mph = 2.236936
# hPa to mm Hg
to_mmhg = 0.750062
feels_like = mc.feels_like(temperature=temp, humidity=humidity, wind_speed=wind_speed * to_mph).c
print('{}°({}°) {}, {}m/s, {}%, {}, {}mmHg'.format(
int(temp),
int(feels_like),
w.get_detailed_status(),
wind_speed,
humidity,
w.get_rain(),
int(w.get_pressure()['press'] * to_mmhg)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment