Example #1
0
 def get(self):
     # List Cities
     citylist = {}
     cities = City.all()
     for city in cities:
         citylist[city.Name] = {0:abs(hash(city.Name)),1:[]}
         for station in city.station_set:
             data = {'Name':station.Name}
             query = Query(AQIData)
             query.filter('Station =', station.Code)
             query.order('-Date')
             query.run()
             aqi = query.get()
             data['AQI'] = aqi.AQI
             data['Level'] = aqi.AQILevel
             data['Assess'] = aqi.AQIAssess
             data['Majority'] = aqi.Majority
             data['Date'] = aqi.Date
             citylist[city.Name][1].append(data)
     # logging.info(str(citylist))
     #----generate parameter list----------------------------------------------------------------------
     template_values = {
         'citylist' : citylist,
         }
     path = os.path.join(os.path.dirname(__file__), './/template//citylist.html')
     #----end------------------------------------------------------------------------------------------
     self.response.out.write(template.render(path,template_values))
Example #2
0
    def get(self):
        # get city id
        city_id = self.request.get('city','')
        try:
            city_id = int(city_id)
        except:
            city_id = 0

        if city_id == 0:
            # no city? --> show city list
            citylist = {}
            cities = City.all()
            for city in cities:
                citylist[city.Name] = [city.Code,abs(hash(city.Name))]
            #----generate parameter list----------------------------------------------------------------------
            template_values = {
                'citylist' : citylist,
                'stationlist' : None
                }
            path = os.path.join(os.path.dirname(__file__), './/template//citylist_all.html')
            #----end------------------------------------------------------------------------------------------
            self.response.out.write(template.render(path,template_values))
        else:
            # show station plots
            stationlist = {}
            query = Query(City)
            query.filter('Code =', city_id)
            query.run()
            city = query.get()
            for station in city.station_set:
                data = []
                query = Query(AQIData)
                query.filter('Station =', station.Code)
                query.order('-Date')
                query.run()
                aqi = query.fetch(None)
                for entry in aqi:
                    data.append("['%s',%d]" % (str(entry.Date),entry.AQI))
                stationlist[station.Name] = ','.join(data)
            #----generate parameter list----------------------------------------------------------------------
            template_values = {
                'citylist' : None,
                'stationlist' : stationlist
                }
            path = os.path.join(os.path.dirname(__file__), './/template//citylist_all.html')
            #----end------------------------------------------------------------------------------------------
            self.response.out.write(template.render(path,template_values))
def check_and_write_row(row_d):
    """
    Check and save @row_d, return True if ok and False if failed.
    """
    row_acceptable = bool(row_d['Date Password Provided'])
    if row_acceptable:
        # get org
        query = Query(model_class=Organization)
        query.filter('name = ', row_d['ORGANIZATION'])
        org = query.get()
        if org:
            try:
                # write new contact
                new_contact = Contact(
                    first_name=row_d['First Name'],
                    last_name=row_d['Last Name'],
                    email=row_d['E-MAIL'],
                    phone=row_d['PHONE #'],
                    organization=org,
                )
                new_contact.save()
                return True
            except BadValueError, e:
                pass