Snoweye.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:CAM2RetrieveData 作者: PurdueCAM2Project 项目源码 文件源码
def gAPI(self, locat, region, main_location, country, link, f, g):
        time.sleep(0.2);
        geolocator = GoogleV3(api_key = 'AIzaSyDRb6HaVtHDbpHkJq8a3MEODFZlmkBt7f4')
        if country != 'USA':
            try:
                searchTerm = str(locat + region + ',' + country)
                location = geolocator.geocode(searchTerm)
            except:
                searchTerm = str(main_location + ',' + country)
                location = geolocator.geocode(searchTerm)
            extractCity = location.raw['address_components'] #Get the raw JSON information so that the city name can be extracted
            city = locat
            for item in extractCity:
                types = item['types']
                if types[0] == "locality":
                    city = item['long_name']
            locat = country+'#'+str(city).decode("utf-8")+'#'+link+'#'+str(location.latitude)+'#'+str(location.longitude)
            f.write(locat.encode('utf-8').replace(" ","").replace("\n",'')+'\n')
        else:
            try:
                searchTerm = str(locat + region + ',' + main_location)
                location = geolocator.geocode(searchTerm)
            except:
                raise Exception
            extractCityState = location.raw['address_components'] #Get the raw JSON information so that the city name can be extracted
            city = locat
            state = ""
            for item in extractCityState:
                types = item['types']
                if types[0] == "locality":
                    city = item['long_name']
                elif types[0] == "administrative_area_level_1":
                    state = item['short_name']
            if state == "":
                raise Exception('No State!')
            locat = 'USA#'+str(state)+'#'+str(city).decode("utf-8")+'#'+link+'#'+str(location.latitude)+'#'+str(location.longitude)
            g.write(locat.encode('utf-8').replace(" ","").replace("\n",'')+'\n')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号