Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split helper methods out into their own modules (and source files).
- Loading branch information
Showing
7 changed files
with
62 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import urllib2 | ||
|
||
from google.appengine.api import urlfetch | ||
|
||
APP_ID = "OSkXnanV34GmWWqcfpA2CsbB18xDtJF6_mfp7Su.HpqXelHWX.ipRGVAe.dw1j8-" | ||
|
||
def fetch(url): | ||
result = urlfetch.fetch(url, method=urlfetch.GET, headers={"Accept": "application/xml"}) | ||
if result.status_code != 200: | ||
raise models.GeoError(result.status_code) | ||
else: | ||
return result.content | ||
|
||
def place_for_search_term(search_term): | ||
search_term = urllib2.quote("'%s'" % search_term) | ||
return fetch("http://where.yahooapis.com/v1/places.q(%s)?appid=%s" % (search_term, APP_ID)) | ||
|
||
def parent_of_place(place): | ||
return fetch("http://where.yahooapis.com/v1/place/%s/parent?appid=%s" % (place, APP_ID)) | ||
|
||
def children_of_place(place, **kwargs): | ||
kwlist = {'type': -1} | ||
kwlist.update(kwargs) | ||
type = kwlist['type'] | ||
return fetch("http://where.yahooapis.com/v1/place/%s/belongtos.type(%s)?appid=%s" % (place, type, APP_ID)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from google.appengine.api import urlfetch | ||
|
||
def cap_for_state(state): | ||
result = urlfetch.fetch("http://www.weather.gov/alerts/%s.cap" % state.lower()) | ||
if result.status_code != 200: | ||
raise models.CAPError(result.status_code) | ||
else: | ||
return result.content | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.utils import simplejson as json | ||
|
||
class AlertEncoder(json.JSONEncoder): | ||
|
||
def default(self, o): | ||
return { | ||
'place': { | ||
'name': o.place.named, | ||
'county': o.place.county, | ||
'state': o.place.state, | ||
'timezone': o.place.timezone | ||
}, | ||
'event': o.event, | ||
'effective': o.effective, | ||
'expires': o.expires, | ||
'severity': o.severity | ||
} | ||
|