Skip to content

Instantly share code, notes, and snippets.

@whoizit
Last active August 14, 2019 15:26
Show Gist options
  • 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