-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeatherCommands.py
More file actions
69 lines (52 loc) · 2.3 KB
/
WeatherCommands.py
File metadata and controls
69 lines (52 loc) · 2.3 KB
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
67
68
69
#https://github.com/csparpa/pyowm
import pyowm
owm = pyowm.OWM('665d0497ac66c8c8cfd2178807d07f57')
commandlist = [['+wn', 'get current weather. Accepts zip codes (US only) or places (format: city,country)']]
def help():
output = ""
for entry in commandlist:
output += ('Use "%s" to %s! \n' % (entry[0],entry[1]))
return output
def current_weather_z(zip, country='us', unit='fahrenheit'):
zip = zip.strip()
observation = owm.weather_at_zip_code(zip,country)
w = observation.get_weather()
temperature = w.get_temperature(unit)
status = w.get_status()
location = observation.get_location()
name = location.get_name() + ', ' + location.get_country()
out = '''
Showing information for: **%s**!
The temperature right now is: **%s**°F
The weather status is: **%s**
Today's low is **%s**°F and the high for today is going to be **%s**°F :smile:
''' % (name,temperature['temp'],status,temperature['temp_min'],temperature['temp_max'])
return out
def current_weather_p(location):
location = location.lower().strip().split(',')
city,country = location[0],location[1]
observation = owm.weather_at_place('%s,%s' % (city,country))
w = observation.get_weather()
location = observation.get_location()
name = location.get_name() + ', ' + location.get_country()
if location.get_country().lower() == 'us':
unit = 'fahrenheit'
temperature = w.get_temperature(unit)
status = w.get_status()
out = '''
Showing information for: **%s**!
The temperature right now is: **%s**°F
The weather status is: **%s**
Today's low is **%s**°F and the high for today is going to be **%s**°F :smile:
''' % (name,temperature['temp'],status,temperature['temp_min'],temperature['temp_max'])
else:
unit = 'celsius'
temperature = w.get_temperature(unit)
status = w.get_status()
out = '''
Showing information for: **%s**!
The temperature right now is: **%s**°C
The weather status is: **%s**
Today's low is **%s**°C and the high for today is going to be **%s**°C :smile:
''' % (name,temperature['temp'],status,temperature['temp_min'],temperature['temp_max'])
return out