forked from kuri65536/python-for-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsay_weather.py3
More file actions
31 lines (24 loc) · 922 Bytes
/
Copy pathsay_weather.py3
File metadata and controls
31 lines (24 loc) · 922 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
"""Speak the weather."""
__author__ = 'T.V. Raman <raman@google.com>'
__copyright__ = 'Copyright (c) 2009, Google Inc.'
__license__ = 'Apache License, Version 2.0'
import android
import weather
def say_weather(droid):
"""Speak the weather at the current location."""
msg = 'Failed to find location.'
location = droid.getLastKnownLocation().result
location = location.get('gps') or location.get('network')
if location is not None:
print('Finding ZIP code.')
addresses = droid.geocode(location['latitude'], location['longitude'])
zip = addresses.result[0]['postal_code']
if zip is not None:
print('Fetching weather report.')
result = weather.fetch_weather(zip)
# Format the result for speech.
msg = '%(temperature)s degrees and %(conditions)s, in %(city)s.' % result
droid.ttsSpeak(msg)
if __name__ == '__main__':
droid = android.Android()
say_weather(droid)