Example #1
0
def setTeamGeoLocation(session, team_key=None):
    
    teams = session.query(TeamInfo).filter(TeamInfo.team>0).all()
    
    geo_locations_found = 0
    for team in teams:
        # some teams in the database don't have complete information, so skip
        # those that don't list an address location
        if team.location != '' and team.geo_location is None:
            print 'Getting Geo Location For Team: FRC%d' % team.team
            try:
                # check to see if we haven't already obtained the geo location and
                # skip those that have already been set. The Google APIs have usage
                # limits so we're going to have to do this a piece at a time
                geo_location = GoogleMapsIntf.get_geo_location( team.location )
                
                # if the location is not found, let's massage the location and try again
                if geo_location is None:
                    if 'USA'  in team.location:
                        print 'Skipping team FRC%d From %s' & (team.team,team.location)
                    else:
                        split_location = team.location.split(',')
                        if len(split_location) > 2:
                            new_location = split_location[0] + ',' + split_location[-1]
                            geo_location = GoogleMapsIntf.get_geo_location( new_location )
                        
                #if len(geo_location) != 2:
                #    raise
                if geo_location is not None:
                    geo_location_json = json.dumps(geo_location)
                    team.geo_location = geo_location_json
                
                    print 'Geo Location For FRC%d: %s' % (team.team, geo_location_json)
                
                    geo_locations_found += 1
            
                    # commit each location as it is found so that we don't lose any
                    # should an exception be raised
                    session.commit()        
                    
            except:
                print 'Error Getting Geo Location For Team: FRC%d' % team.team
                #break
                
            # pause between each request to ensure that we don't exceed the rate in which we
            # call the Google APIs
            time.sleep(1)
            
    print 'Successful Geo Location Lookups: %d ' % geo_locations_found
    
    return
Example #2
0
def setEventsGeoLocation(session, event_key=None):
    
    events = session.query(EventInfo).all()
    
    for event in events:
        try:
            if 'Mexico' in event.location:
                print 'Location: %s' % event.location
                
            if event.geo_location is None or event.geo_location == 'null':
                print 'Getting Geo Location For Event: %d %s' % (event.event_year,event.name)
                geo_location = GoogleMapsIntf.get_geo_location( event.location )
                geo_location_json = json.dumps(geo_location)
                event.geo_location = geo_location_json
            
                session.commit()
                
                time.sleep(1)

        except:
            print 'Error Getting Geo Location For Event: %s' % event.name
            

    return