forked from kuri65536/python-for-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotify_weather.py
More file actions
32 lines (26 loc) · 968 Bytes
/
Copy pathnotify_weather.py
File metadata and controls
32 lines (26 loc) · 968 Bytes
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
"""Display the weather report in a notification."""
__author__ = 'Damon Kohler <damonkohler@gmail.com>'
__copyright__ = 'Copyright (c) 2009, Google Inc.'
__license__ = 'Apache License, Version 2.0'
import android
import weather
def notify_weather(droid):
"""Display the weather at the current location in a notification."""
print 'Finding ZIP code.'
location = droid.getLastKnownLocation().result
if location['gps'] is not None:
location = location['gps']
else:
location = location['network']
addresses = droid.geocode(location['latitude'], location['longitude'])
zip = addresses.result[0]['postal_code']
if zip is None:
msg = 'Failed to find location.'
else:
print 'Fetching weather report.'
result = weather.fetch_weather(zip)
msg = '%(temperature)s degrees and %(conditions)s, in %(city)s.' % result
droid.notify('Weather Report', msg)
if __name__ == '__main__':
droid = android.Android()
notify_weather(droid)