Beispiel #1
0
        def commit_data(self,data,metric_data,imperial_data):
            
        
        #Prep model objects
            loc = Location()
            temp_data = Temperature()
            wind_data = WindSpeed()

        #Assign location fields from collected json data
            loc.longitude = data[u'coord'][u'lon']
            loc.latitude = data[u'coord'][u'lat']
            loc.city_id = data[u'id']
            loc.city_name = data[u'name']
        
        #Insert Location if it does not already exist
        
            try:
                comp = Location.objects.get(city_id = data[u'id'])
            except:
                loc.save()
            else:   
                print "location exists"
        
        
        #Assign temperature fields from collected json data
            temp_data.temp_min = Decimal(data[u'main'][u'temp_min'])
            temp_data.temp_max = Decimal(data[u'main'][u'temp_max'])
            temp_data.temp = Decimal(data[u'main'][u'temp'])
            temp_data.temp_min_imperial = Decimal(imperial_data[u'main'][u'temp_min'])
            temp_data.temp_max_imperial = Decimal(imperial_data[u'main'][u'temp_max'])
            temp_data.temp_imperial = Decimal(imperial_data[u'main'][u'temp'])
            temp_data.temp_min_metric = Decimal(metric_data[u'main'][u'temp_min'])
            temp_data.temp_max_metric = Decimal(metric_data[u'main'][u'temp_max'])
            temp_data.temp_metric = Decimal(metric_data[u'main'][u'temp'])
            temp_data.location = Location.objects.get(city_id = loc.city_id)
        
        #Save temperature data
            temp_data.save()
        
        #Assign windspeed fields from collected json data
            wind_data.location = Location.objects.get(city_id = loc.city_id)
            wind_data.wind_speed = Decimal(data[u'wind'][u'speed'])
            wind_data.degree = Decimal(data[u'wind'][u'deg'])
            wind_data.wind_speed_imperial = Decimal(imperial_data[u'wind'][u'speed'])
            wind_data.degree_imperial = Decimal(imperial_data[u'wind'][u'deg'])
            wind_data.wind_speed_metric = Decimal(metric_data[u'wind'][u'speed'])
            wind_data.degree_metric = Decimal(metric_data[u'wind'][u'deg'])
        
        #Save windspeed data
            wind_data.save()
Beispiel #2
0
        def commit_data_loc(self,data):
        
        #Prep model objects
            loc = Location()

        #Assign location fields from collected json data
            loc.longitude = data[u'coord'][u'lon']
            loc.latitude = data[u'coord'][u'lat']
            loc.city_id = data[u'id']
            loc.city_name = data[u'name']
        
        #Insert Location if it does not already exist
        
            try:
                comp = Location.objects.get(city_id = data[u'id'])
            except:
                loc.save()
            else:   
                print "location exists"