My favorites
▼
|
Sign in
android-scripting
Scripting Layer for Android brings scripting languages to Android.
Project Home
Downloads
Wiki
Issues
Source
Repository:
default
wiki
Checkout
Browse
Changes
Clones
Source path:
hg
/
python
/
ase
/
scripts
/
weather.py
Branch:
default
Tag:
<none>
r17
r18
r18-1
r19
r20
r21
r22
r23
r24
r25
sl4a_r0
sl4a_r1
sl4a_r2
sl4a_r3
sl4a_r4
cbba71cf9b0d
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
"""Retrieve the weather report for the current location."""
__author__ = 'T.V. Raman <raman@google.com>'
__copyright__ = 'Copyright (c) 2009, Google Inc.'
__license__ = 'Apache License, Version 2.0'
import string
import urllib
import urllib2
from xml.dom import minidom
WEATHER_URL = 'http://www.google.com/ig/api?weather=%s&hl=%s'
def extract_value(dom, parent, child):
"""Convenience function to dig out weather values."""
return dom.getElementsByTagName(parent)[0].getElementsByTagName(child)[0].getAttribute('data')
def fetch_weather(location, hl=''):
"""Fetches weather report from Google
Args:
location: a zip code (94041); city name, state (weather=Mountain View,CA);...
hl: the language parameter (language code)
Returns:
a dict of weather data.
"""
url = WEATHER_URL % (urllib.quote(location), hl)
handler = urllib2.urlopen(url)
data = handler.read()
dom = minidom.parseString(data)
handler.close()
data = {}
weather_dom = dom.getElementsByTagName('weather')[0]
data['city'] = extract_value(weather_dom, 'forecast_information','city')
data['temperature'] = extract_value(weather_dom, 'current_conditions','temp_f')
data['conditions'] = extract_value(weather_dom, 'current_conditions', 'condition')
dom.unlink()
return data
Show details
Hide details
Change log
e1cf1c7919da
by Damon Kohler <damonkohler> on Aug 4, 2009
Diff
Initial import of source.
Go to:
/LICENSE
...dScriptingEnvironment/.classpath
...oidScriptingEnvironment/.project
...tings/org.eclipse.jdt.core.prefs
...dScriptingEnvironment/Android.mk
...gEnvironment/AndroidManifest.xml
...vironment/MODULE_LICENSE_APACHE2
...droidScriptingEnvironment/NOTICE
...ngEnvironment/default.properties
...onment/doc/allclasses-frame.html
...ment/doc/allclasses-noframe.html
...om/google/ase/AndroidFacade.html
...com/google/ase/AndroidProxy.html
...AndroidScriptingEnvironment.html
...com/google/ase/AseException.html
...t/doc/com/google/ase/AseLog.html
...m/google/ase/CircularBuffer.html
...oc/com/google/ase/Constants.html
...oogle/ase/CustomWindowTitle.html
...m/google/ase/IntentBuilders.html
...com/google/ase/LocalePlugin.html
.../doc/com/google/ase/R.array.html
...t/doc/com/google/ase/R.attr.html
...c/com/google/ase/R.drawable.html
...onment/doc/com/google/ase/R.html
...ent/doc/com/google/ase/R.id.html
...doc/com/google/ase/R.layout.html
...t/doc/com/google/ase/R.menu.html
...nt/doc/com/google/ase/R.raw.html
...doc/com/google/ase/R.string.html
.../doc/com/google/ase/R.style.html
.../com/google/ase/R.styleable.html
...nt/doc/com/google/ase/R.xml.html
...com/google/ase/ScriptEditor.html
...com/google/ase/ScriptKiller.html
...om/google/ase/ScriptManager.html
...om/google/ase/ScriptService.html
...le/ase/ScriptStorageAdapter.html
...ase/class-use/AndroidFacade.html
.../ase/class-use/AndroidProxy.html
...AndroidScriptingEnvironment.html
.../ase/class-use/AseException.html
...google/ase/class-use/AseLog.html
...se/class-use/CircularBuffer.html
...gle/ase/class-use/Constants.html
...class-use/CustomWindowTitle.html
...se/class-use/IntentBuilders.html
.../ase/class-use/LocalePlugin.html
...oogle/ase/class-use/R.array.html
...google/ase/class-use/R.attr.html
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 1292 bytes, 44 lines
View raw file
Powered by
Google Project Hosting