-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOpenWeather.py
66 lines (46 loc) · 1.28 KB
/
OpenWeather.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import asyncio
from os import system
import random
import _thread
import sys
from threading import Timer
import os
from datetime import datetime
from dateutil import parser
import pyowm
import pytz
# pip3 install python-dateutil
# pip3 install pyowm
'''
OpenWeather Module
@class OpenWeather
@author - Team Wizards of Coz
'''
class OpenWeather():
pollDuration = 600
timeToEvent = 100
api_key = None
city = None
owm = None
def __init__(self,api_key,city):
self.api_key = api_key
self.city = city
self.owm = pyowm.OWM(api_key)
def getWeatherNow(self):
obs = self.owm.weather_at_place(self.city)
w = obs.get_weather()
return w.get_status()
# fc = self.owm.three_hours_forecast(self.city)
# f = fc.get_forecast()
#
# for weather in f:
# print (weather.get_reference_time('iso'),weather.get_status())
#
# utc_dt = str(date.astimezone(pytz.utc))
# utc_dt = utc_dt[:-3]
#
# return fc.get_weather_at(utc_dt).get_status()
def pollWeather(self):
Timer(self.pollDuration, self.pollWeather).start()
if __name__ == '__main__':
OpenWeather()