Beispiel #1
0
def load_stadiums(session, stadium_filename):
    f = open(stadium_filename, 'r')
    data = yaml.load(f)
    for line in data:
        stadium = Stadium()
        stadium.loadFromYaml(line)
        try:
            session.add(stadium)
            session.commit()
        except IntegrityError:
            session.rollback()
Beispiel #2
0
 def get(self):
     include_club = False
     v = self.request.get('include')
     if v == 'club':
         include_club = True
     stadiums = []
     for s in Stadium.all().order('-location'):
         # Hand-made GeoJSON.
         p = {
             'type': 'Feature',
             'id': None,
             'properties': {
                 'abbr': s.abbr,
                 'name': s.display_name,
                 'wikipedia': s.wikipedia_url
             },
             'geometry': {
                 'type': 'Point',
                 'coordinates': [
                     s.location.lon, s.location.lat
                 ]
             }
         }
         if include_club:
             q = Club.all().filter('stadium =', s.abbr)
             clubs = []
             for c in q:
                 clubs.append({
                     'key': c.key().name(),
                     'category': c.category,
                     'url': c.url,
                     'name': c.display
                 })
             if len(clubs) > 0:
                 p['properties']['clubs'] = clubs
         stadiums.append(p)
     # See IANA official document.
     # http://www.iana.org/assignments/media-types/application/vnd.geo+json
     self.response.headers["Content-Type"] = "application/vnd.geo+json"
     json.dump({'type': 'FeatureCollection', 'features': stadiums},
               self.response.out)