def extractZipCodeInfo(self, entity): geolocator = Bing(api_key="Ar-aTc8AF9MnqnsJAbSHorGLYZUugT5Rd2gmD6Aq6Cd-z-kMzJ71u3Ku7h_s0MNh") zipcode =str(entity) location = geolocator.geocode(zipcode, include_country_code=True, include_neighborhood=True) resonseMSg = "" try : countryValues = location.raw country = countryValues['address']['countryRegionIso2'] print("Country is ", country) try: state = countryValues['address']['adminDistrict'] print("state is ",state) inputValues = str(state)+", "+str(country) compleleteList = geolocator.geocode(inputValues, include_country_code=True, include_neighborhood=True) correctStateName = str(compleleteList.raw['address']['formattedAddress']) #_, count, _ , country= self.getTotalConfirmedCasesInWorld(country,self.CCCases) resonseMSg, _, _, _ = self.getTotalCasesInfo(correctStateName,"All") return resonseMSg except Exception as ex: print(ex) resonseMSg1, _, _, _ = self.getTotalCasesInfo(country, "All") resonseMSg = "Sorry..!! I could not find the details for "+ zipcode.upper() +" \n Instead I am giving the below details " \ " as the "+zipcode.upper()+" belongs to "+country+"\n \n" \ ""+ resonseMSg1 return resonseMSg except Exception as e: print(e) return "Sorry I am not able to recognize the zipcode "+ zipcode
def is_bing_ok(self): try: geocoder = Bing(settings.BING_API_TOKEN, '%s, UK') geo_resp = geocoder.geocode('SW1A 1AA') return True except GeopyError: return False
def add_coordinates(): geolocator = Bing( api_key= "AjqWLHWVCEHcB9V7sO2ubMzKO7P1eARR-Zl6SBe0RmACT5RFMer3p6q6iJxiQ2Z9", timeout=3) # todo: add delay, api requests timing out with open('dataset/locations_export.csv') as csvDataFile: csvReader = csv.reader(csvDataFile) with open('dataset/location_coordinates_complete.csv', 'w') as csv_out: writer = csv.writer(csv_out, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) csvReader = csv.reader(csvDataFile) row_count = 0 for row in csvReader: if row_count % 100 == 0: print(f"sleepy time {row_count}" ) #just to check progress while it's running #time.sleep(1) row_count += 1 if row: if not row[1]: location = geolocator.geocode(query=str(row[0])) if location is not None: new_row = [ row[0], location.latitude, location.longitude ] else: new_row = row else: new_row = row else: new_row = ["", "", ""] writer.writerow(new_row)
def _clean_geo(self): lat = self.cleaned_data.get('lat') lng = self.cleaned_data.get('lng') if not lat or not lng: q = self.cleaned_data.get('q') try: geocoder = Bing(settings.BING_API_TOKEN, '%s, UK') geo_resp = geocoder.geocode(q) except GeopyError: raise UnexpectedException() if not geo_resp: raise UnexpectedException() placename, (lat, lng) = geo_resp # Bing Maps API turns a placename of "United Kingdom" for invalid # postcodes that _look_ like a valid postcode - e.g. first text # part (SW, SE) followed by regex-matching pattern. Along with the # placename, it returns a lat/lon of the middle of the country, # which is somewhere in Durham. if placename == 'United Kingdom': raise UnexpectedException() self.cleaned_data['lat'] = lat self.cleaned_data['lng'] = lng return (lat, lng)
def getCountry(text): #geo_keys = 'name1', 'name2', 'name3', 'name4', 'name5', n # ] # Put in your API keys as strings key = 'AkuTMRwxGjK2-wtHvgeCMcAoYBVvEB0XF0CaW-q_7u2EHSIfVhKHCwlD5FtF63FR' if text[0] == 'NIL': value = text[1] else: value = text[0] from geopy.geocoders import Bing #geopy.geocoders.options.default_proxies = {"http": "http://37.48.118.4:13010"} geolocator = Bing(api_key=key) geocode = RateLimiter(geolocator.geocode, min_delay_seconds=1) location = geocode(value) if location is not None: location = location.raw else: return 'None' #geocode = RateLimiter(geolocator.reverse, min_delay_seconds=1) #lat = location['lat'] #lon = location['lon'] #location = geocode((lat, lon), language='en', exactly_one=True) #location = location.raw #country = location['address']['country'] try: country = location['address']['countryRegion'] return country except KeyError: return text
def get_tweets(): locator = Bing( "Ah0nnAJPsuz_GDQuwBEQ0xplFqJy7MsoCwLGDmTyZwA_RcTKsQKPY0X0MFf3rh5j") for event in dates.keys(): nums = {} times = 1 amount = 100 criteria = got.manager.TweetCriteria().setSince( dates[event][0]).setUntil(dates[event][1]).setQuerySearch("sailgp") print(len(got.manager.TweetManager.getTweets(criteria))) break # tweets = api.search_full_archive("dev", "sailgp", fromDate=dates[event][0], toDate=dates[event][1], maxResults=amount) # check_tweets(tweets, nums, locator) # tweets = api.search_full_archive("dev", "sailgp", fromDate=dates[event][0], toDate=dates[event][1], maxResults=amount) # while len(tweets) == amount: # times += 1 # final_date = check_tweets(tweets, nums, locator) # tweets = api.search_full_archive("dev", "sailgp", fromDate=final_date, toDate=dates[event][1], maxResults=amount) # print(times) # print(event) data[event] = nums with open("output.json", "w") as f: f.write(json.dumps(data))
def getMapUrl(self, entity, zoom=7): dynamicMapUrl = "https://www.mapquestapi.com/staticmap/v4/getmap?key=lYrP4vF3Uk5zgTiGGuEzQGwGIVDGuy24" \ "&size=600,600&type=map&imagetype=jpg&zoom=#zoom&scalebar=false&traffic=false" \ "¢er=#center" \ "&xis=https://s.aolcdn.com/os/mapquest/yogi/icons/poi-active.png,1,c,40.015831,-105.27927&ellipse=fill:0x70ff0000|color:0xff0000|width:2|40.00,-105.25,40.04,-105.30" try: zoom = str(zoom) dynamicMapUrl = requote_uri(dynamicMapUrl) geolocator = Bing( api_key= "Ar-aTc8AF9MnqnsJAbSHorGLYZUugT5Rd2gmD6Aq6Cd-z-kMzJ71u3Ku7h_s0MNh" ) location = geolocator.geocode(entity, include_country_code=True) lat = location.raw['point']['coordinates'][0] long = location.raw['point']['coordinates'][1] latValues = str(lat) + "," + str(long) dynamicMapUrl = dynamicMapUrl.replace("#center", latValues) dynamicMapUrl = dynamicMapUrl.replace("#zoom", zoom) responseValue = "$$$" + dynamicMapUrl print(dynamicMapUrl) # response = requests.get(dynamicMapUrl) # if(response.status_code==200): # responseValue = "$$$"+ response.text # else: # responseValue= "" except Exception as ex: print(ex) responseValue = "" return responseValue
def get_lat_long(location): locator = Bing(_internal['geocode_key']) location = locator.geocode(location) coordinates = {} if location != None: coordinates['latitude'] = location.latitude coordinates['longitude'] = location.longitude return coordinates
def findCoordinates(KEY, DATASET_PATH, SAVELOCATION_PATH, TOP_LIMIT=120, isNoRetweet=False): print("*****Outsourcing Work To Get Location's Coordinates*****") print("¥[*.*]¥ -- > Gonna Hire A Bangladeshi Guy") print("¥[*.*]¥ -- > #metooLAZY") print("¥[*.*]¥ -- > Also Trump don't deport my guy !!PLEASE!!") print("") print("") if isNoRetweet: DATASET_PATH = DATASET_PATH + "/withoutRT" SAVELOCATION_PATH = SAVELOCATION_PATH + "/withoutRT" os.makedirs(SAVELOCATION_PATH, exist_ok=True) geolocator = Bing(api_key=KEY) user_location = pd.read_csv(DATASET_PATH + '/user_location.csv') user_location = removeRow(user_location, "Earth") user_location = removeRow(user_location, "Worldwide") user_location = removeRow(user_location, "Global") user_location = removeRow(user_location, "Planet Earth") user_location = removeRow(user_location, "Everywhere") user_location = removeRow(user_location, ".") user_location = removeRow(user_location, "she/her") user_location = removeRow(user_location, "In Hearts of") user_location = removeRow(user_location, "Mars") user_location = removeRow(user_location, "Hogwarts") user_location = removeRow(user_location, "worldwide") user_location = removeRow(user_location, "Worldwide") df = pd.DataFrame(columns=['place', 'lat', 'long', 'type']) retryCount = 0 for i in user_location.iloc[0:TOP_LIMIT, 0]: while True: try: location = geolocator.geocode(i) print((i.encode("utf-8"), location.latitude, location.longitude, location.raw['entityType'])) df = df.append({'place': i, 'lat': location.latitude, 'long': location.longitude, 'typegg': location.raw['entityType']}, ignore_index=True) time.sleep(0.5) retryCount = 0 break except: retryCount += 1 if retryCount > 20: print("Stuck on Error for too long") print("Exiting now") retryCount = 0 break print("---------------------ERROR----------------") continue print("") print("( ^◡^)っ ---> I am done sir,") print("") print("¥[*.*]¥ -- > Thank you Sayeed") print("") print("( ^◡^)っ ---> Dhonno-baad") print("") print("") df.to_csv(SAVELOCATION_PATH + "/user_location_coordinates.csv")
def _geocode_address_using_backup(address): ''' Gets the longitude and latitude of address for plotting on a map from backup service (Bing) ''' try: bing_locator = Bing(api_key=settings.BING_MAPS_API_KEY) return bing_locator.geocode(address) except: return
def geocode_address(address): address = address.encode('utf-8') geocoder = Bing( api_key= 'AmTOjxQXZeKHxacoFI3IoPyR6PHW0U-r0NgDSQ8F-x0dt97mnLMFKREiS96mkOkX') try: location = geocoder.geocode(address) except (URLError, GeocoderServiceError, ValueError): pass else: return location
def geocode(address, address2, city, state, postcode, country): ''' Geocode an address; returns dict with lat, lon, and postcode ''' if is_empty(address): print("Need an address to geocode!") return None geoaddress = address if not is_empty(address2): geoaddress += "," + address2 if not is_empty(city): geoaddress += "," + city if not is_empty(state): geoaddress += "," + state if not is_empty(postcode): geoaddress += "," + postcode if not is_empty(country): geoaddress += "," + country if config.bing_geocoder_api_key is not None: geolocator = Bing(api_key=config.bing_geocoder_api_key, timeout=30) location = geolocator.geocode(geoaddress, exactly_one=True) if location is not None: return { "lat": location.latitude, "lon": location.longitude, "zip": get_zip_from_bing_location(location) } else: print("Bing could not geocode address") else: print("Skipping Bing geocoder because we don't have a free API key") if config.google_geocoder_api_key is not None: geolocator = GoogleV3(api_key=config.google_geocoder_api_key, timeout=30) location = geolocator.geocode(geoaddress) if location is not None: return { "lat": location.latitude, "lon": location.longitude, "zip": get_zip_from_google_location(location) } else: print("Google could not geocode address") else: print("Skipping Google geocoder because we don't have a free API key") return None
def save(self, **kwargs): if not self.location: address = u'%s %s' % (self.city, self.address) address = address.encode('utf-8') geocoder = Bing(api_key='AmTOjxQXZeKHxacoFI3IoPyR6PHW0U-r0NgDSQ8F-x0dt97mnLMFKREiS96mkOkX') try: _, latlon = geocoder.geocode(address) except (URLError, GeocoderServiceError, ValueError): pass else: point = "POINT(%s %s)" % (latlon[1], latlon[0]) self.location = geos.fromstr(point) super(Shop, self).save()
def zipcode(): if request.method == 'GET': return render_template('zipcoding.html') else: # request was a POST #app.vars['pandas'] = request.form['keyword'] file = request.files.get("data_file") if file.filename.endswith('.csv'): df = pd.read_csv(file) else: df = pd.read_excel(file) g = Bing( 'AoGg6nfFsORF7WrNxkvEQpj2r-O7WTS5hoOYXg6fDynZIo4JkGcFZ-UPjPJ7HQda', timeout=5) df2 = df.drop_duplicates(subset=['latitude', 'longitude'], keep='first') reverse = df2[['latitude', 'longitude']] reverse_list = reverse.values.tolist() zips = [] import geocoder # pip install geocoder for i in reverse_list: g = geocoder.bing( i, method='reverse', key= 'AoGg6nfFsORF7WrNxkvEQpj2r-O7WTS5hoOYXg6fDynZIo4JkGcFZ-UPjPJ7HQda' ) try: zips.append(g.postal) except: zips.append('N/A') reverse['zipcode'] = zips reverse = reverse.reset_index() #reverse = reverse.drop('action_timestamp', 1) result = pd.merge(df, reverse, how='left', on=['latitude', 'longitude']) result resp = make_response(result.to_csv()) resp.headers[ "Content-Disposition"] = "attachment; filename=export_zip.csv" resp.headers["Content-Type"] = "text/csv" return resp
def get_geoBLOB(self, locationString, geolocator = Bing("AoHjJBfB_lnIWNP201cRJ70AItSb0hRGuIv2YvGpEOtUmDe41W9kghqEdUlZcMQz")): try: #first check cache for geoBLOB geoBLOB = self.location_cached(locationString) #if no row found, call geocoder and save results to cache if geoBLOB == False: print("querying: \'", locationString, "\'", sep='') geoBLOB = geolocator.geocode(query = locationString.translate({ord(c): None for c in '<>'}), #<> cause errors in Bing exactly_one=True, include_country_code=True) geoBLOB = self.save_to_cache(locationString, geoBLOB) return(geoBLOB) except Exception as inst: print("ERROR: For locationString = \'",locationString,"\', the following error was encountered: ", inst, sep='')
def get_coder(d): if isinstance(d, str): if d == "Nominatim": return Nominatim() else: raise ValueError("Unknown geocoder '{0}'".format(d)) elif isinstance(d, tuple): name, key = d if name == "bing": return Bing(key) else: raise ValueError("Unknown geocoder '{0}'".format(d)) else: raise TypeError("Unexpected type '{0}'".format(type(d)))
def get_coder(d): if isinstance(d, str): if d == "Nominatim": return Nominatim(user_agent="actuariat_python") raise ValueError( # pragma: no cover "Unknown geocoder '{0}'".format(d)) if isinstance(d, tuple): name, key = d if name == "bing": return Bing(key) raise ValueError( # pragma: no cover "Unknown geocoder '{0}'".format(d)) raise TypeError( # pragma: no cover "Unexpected type '{0}'".format(type(d)))
def getDetailsByPincode(self, entity): geolocator = Bing( api_key= "Ar-aTc8AF9MnqnsJAbSHorGLYZUugT5Rd2gmD6Aq6Cd-z-kMzJ71u3Ku7h_s0MNh") zipcode = str(entity) location = geolocator.geocode(zipcode, include_country_code=True, include_neighborhood=True) resonseMSg = "" try: countryValues = location.raw country = "IN" if (re.fullmatch( r'\d{6}', zipcode)) else countryValues['address']['countryRegionIso2'] print("Country is ", country) try: if (country == "IN"): response = requests.get( "https://api.postalpincode.in/pincode/" + zipcode) if (response.status_code == 200): data = response.json() correctStateName = data[0]['PostOffice'][0]['State'] correctStateName = "Puducherry" if ( str(correctStateName).lower() == "pondicherry") else correctStateName correctStateName = "Telengana" if ( str(correctStateName).lower() == "telangana") else correctStateName print(correctStateName) else: correctStateName = country resonseMSg, _, _, _ = self.getTotalCasesInfo( correctStateName, "All") #resonseMSg +=self.getMapUrl(country) return resonseMSg except Exception as ex: print(ex) resonseMSg1, _, _, _ = self.getTotalCasesInfo(country, "All") resonseMSg = "Sorry..!! I could not find the details for "+ zipcode.upper() +" \n Instead I am giving the below details " \ " as the "+zipcode.upper()+" belongs to "+country+"\n \n" \ ""+ resonseMSg1 resonseMSg += self.getMapUrl(country, zoom=4) return resonseMSg except Exception as e: print(e) return "Sorry I am not able to recognize the zipcode " + zipcode
def geocode(): if request.method == 'GET': return render_template('geocoding.html') else: # request was a POST #app.vars['pandas'] = request.form['keyword'] file = request.files.get("data_file") if file.filename.endswith('.csv'): df = pd.read_csv(file) else: df = pd.read_excel(file) #api_key2 = request.form.get("api_key") #return "uploaded ok" #df['videoID'] = df['URL'].apply(getid) #vidids = df['videoID'].tolist() g = Bing( 'AoGg6nfFsORF7WrNxkvEQpj2r-O7WTS5hoOYXg6fDynZIo4JkGcFZ-UPjPJ7HQda', timeout=5) ddict = {} #create a list of adresses from your column name, then loop through that list adr = df['Address'] for inputAddress in adr: #get the geocode & append it to list try: location = g.geocode(inputAddress, timeout=10) ddict[inputAddress] = [location.latitude, location.longitude] except: ddict[inputAddress] = ["", ""] df2 = pd.DataFrame.from_dict(ddict, orient='index', columns=['lat', 'long']).reset_index() result = pd.merge(df, df2, how='left', left_on='Address', right_on='index').drop("index", 1) #df = df3.to_json() #session['data'] = df resp = make_response(result.to_csv()) resp.headers["Content-Disposition"] = "attachment; filename=export.csv" resp.headers["Content-Type"] = "text/csv" return resp
def reverse_geocode_flickr(self, user_info, wild_collection): # add the encounter locations to our user info dictionaries # which already contain user location for dic in user_info: doc_res = self.db[wild_collection].find({'id': dic['id']}) for doc in doc_res: dic['enc_lat'] = doc['latitude'] dic['enc_long'] = doc['longitude'] #create a df from our user_info list of dictionaries df = pd.DataFrame(user_info) #use bing geocoder to convert cities/countries -> lat, long coords key = 'AsmRvBYNWJVq55NBqUwpWj5Zo6vRv9N_g6r96K2hu8FLk5ob1uaXJddVZPpMasio' locator = Bing(key) user_locs = [] enc_locs = [] #df where there are videos in tf that have BOTH encounter and user loc df_both_locs = df.loc[(df.enc_long != 0) & (df.user_location != None) & (df.user_location != '')] df_both_locs = df_both_locs.reset_index(drop=True) #get user country lat long coords user_lat = [] user_long = [] for x in df_both_locs.user_location.values: if (x == ''): print('empty') continue try: user_lat.append(locator.geocode(x, timeout=3).latitude) user_long.append(locator.geocode(x, timeout=3).longitude) except AttributeError: user_lat.append(None) user_long.append(None) #drop rows in df where user_lat = None, user_long = None # rows = df_both_locs.loc[df_both_locs.user_lat == None or df_both_loc.user_location == ''] # print(rows) # df_both_locs = df_both_locs.loc[df_both_locs.user_lat == None or df_both_loc.user_location == ''] # df_both_locs.drop(rows) #add enc_coords list and user_coords list to df_both_locs df_both_locs['user_lat'] = user_lat df_both_locs['user_long'] = user_long return df_both_locs
def bing(self, addr, local, country, saveraw): output = self.initOutput() # create query address = "" if addr is None else addr address = address + ("" if local is None else "," + local) address = address + ("" if country is None else "," + country) # init service if not init yet if not self.geolocator_bing: self.geolocator_bing = Bing( api_key=self.SERVICES[self.CURRENT_SERVICE]['key']) # geocode address location = self.geolocator_bing.geocode( address, exactly_one=False) #culture='PT', include_neighborhood=True, if location is not None: answer = location[0].raw output['status'] = "OK" output["latitude"] = location[0].latitude output["longitude"] = location[0].longitude output["number_of_results"] = len(location) if answer.get("address"): output["formatted_address"] = answer.get('address').get( 'formattedAddress') output["localidade"] = answer.get("address").get("locality") output["distrito"] = answer.get("address").get("adminDistrict") output["concelho"] = answer.get("address").get( "adminDistrict2") output["freguesia"] = answer.get("address").get("neighborhood") output["postcode"] = answer.get("address").get("postalCode") output["accuracy"] = answer.get('confidence') output["input_string"] = address output["service"] = self.SERVICES[self.CURRENT_SERVICE]['service'] if saveraw: output["response"] = location[0].raw else: output['status'] = "ZERO_RESULTS" return output
def geocoding(addr, flag='b'): res = None if flag == 'b': locator = Bing(BING_API_KEY) na = locator.geocode(query=addr, timeout=10, culture='en') if na is not None: q = na.address.split(",") n = len(q) if n < 4: res = addr else: res = ",".join([q[0], q[1]]) else: res = addr elif flag == 'g': locator = GoogleV3() elif flag == 'n': locator = Nominatim() return res
def get_image_location_name(filename): country = None city = None with open(filename, 'rb') as file: data = exifread.process_file(file) if data: #logger.debug("data {}".format(data)) (lat, lon) = get_exif_location(data) logger.debug("lat={}, lon={}".format(lat, lon)) if lat and lon: geolocator = Bing( "Anoh-j0qAKYh64FthGAOOFjyXExe3uf5D1L2qtPAEenOMna-IYXVH_0khZNQlHJH" ) location = geolocator.reverse(Point(lat, lon), True, 20) logger.info(location.address) else: logger.debug("no EXIF in file {}".format(filename)) return country, city
def convert_to_coordinates(dictionary): """ (None) -> None Connects with API and returns dictionary with coordinates dictionary: name - coordinates in tuple >>> convert_to_coordinates({'Betrayal': 'New Orleans Louisiana USA'}) {'Betrayal': (29.9536991119385, -90.077751159668)} """ geolocator = Bing( "AomOhTUAKsV-5fu4bzeuBtVlx5VeMi_M86P4gODXuCd6f7S2dquidP7Aj2xtDoS0") dict_coordinates = {} for key in dictionary: point = dictionary[key] try: address, (latitude, longitude) = geolocator.geocode(point) dict_coordinates[key] = (latitude, longitude) except TypeError: continue return dict_coordinates
def __init__(self, config_path='geopyplus.cfg'): config = None with open(config_path, 'r') as config_file: config = json.load(config_file) self.providers = [] self.current_index = -1 # The APIs will be used in the order that they are in the configuration file for provider, attributes in config['providers'].iteritems(): if provider == 'google': self.providers.append(GoogleV3(api_key=attributes['api_key'])) elif provider == 'bing': self.providers.append(Bing(api_key=attributes['api_key'])) elif provider == 'mapquest': self.providers.append(MapQuest(api_key=attributes['api_key'])) else: continue self.current_index += 1 self.current_index = 0
def getGeo(street, city, state, zipCode=""): #Nominatim is fussier at street level than Bing. time.sleep(1) zipCode = zipCode if zipCode != None else "" with open('../keys/bingKey.txt') as f: bingKey = f.read() geoloc = Bing(bingKey) place = ("%s, %s, %s %s" % (street, city, state, zipCode)).strip() address = geoloc.geocode(query=place, timeout=10) if not address: #If fails, abandon street and just go for the city's coords print("Bing maps can't find %s. Trying again without street." % place) address = geoloc.geocode(query="%s, %s %s" % (city, state, zipCode)) #print (address.raw) #Return original zipcode if it exists, otherwise computes it. zipCode = zipCode if zipCode != "" else ( address.raw['address']['postalCode']) try: county = address.raw['address']['adminDistrict2'][:-1] + 'unty' except: county = None return (address.latitude, address.longitude, zipCode, county)
from geopy.geocoders import Bing from geopy.extra.rate_limiter import RateLimiter import pandas as pd from tqdm import tqdm tqdm.pandas() geolocator = Bing(api_key='AtlqFZkg8aISlN-CNOpURU3oLthMK6g166C9gDCO1sc9Cl5njVi1NcGaqwIW21vd') geocode = RateLimiter(geolocator.geocode, min_delay_seconds=0.1) df = pd.read_excel('../data/MCM_NFLIS_Data.xlsx', sheet_name='Data') df = df.groupby('FIPS_Combined').first().reset_index() df['name'] = df['COUNTY'] + ', ' + df['State'] df['location'] = df['name'].progress_apply(geocode) df['latitude'] = df['location'].apply(lambda loc: loc and loc.latitude or 0) df['longitude'] = df['location'].apply(lambda loc: loc and loc.longitude or 0) df = df.reindex(columns=['FIPS_Combined', 'State', 'COUNTY', 'latitude', 'longitude']) df.to_csv('geocode.csv', index=False)
def getTotalCasesInfo(self, entity='All', type="All"): ccases= 0 rcases = 0 dcases = 0 indiaFlag = True entity =str(entity).lower() try: if((entity == None) | (entity== "") | (entity == 'globe') | (entity=="world") | (entity=="All")): url = "https://corona.lmao.ninja/v2/all" entity = "World" else: url1 = "https://api.rootnet.in/covid19-in/stats/latest" responseValue = requests.get(url1) ind_data = responseValue.json() regionalData= ind_data['data']['regional'] statesList= [] data = {} for x in regionalData: states = str(x['loc']).lower() statesList.append(states) entity = str(entity).lower() try: indexMatch = statesList.index(entity) if(indexMatch >= 0): entity = str(entity).title() entity = "**" + entity + "**" data['cases'] =regionalData[indexMatch]['confirmedCasesIndian'] data['recovered'] =regionalData[indexMatch]['discharged'] data['deaths'] =regionalData[indexMatch]['deaths'] data['active'] = 0 #data['countryInfo']['flag'] = "https://raw.githubusercontent.com/NovelCOVID/API/master/assets/flags/in.png" responeMsg,ccases,rcases,dcases = self.formCasesString(data, type, entity) indiaFlag= False except Exception as ex : geolocator = Bing(api_key="Ar-aTc8AF9MnqnsJAbSHorGLYZUugT5Rd2gmD6Aq6Cd-z-kMzJ71u3Ku7h_s0MNh") zipcode = str(entity) location = geolocator.geocode(zipcode, include_country_code=True, include_neighborhood=True) try: entity = location.raw['address']['countryRegion'] url = "https://corona.lmao.ninja/v2/countries/" + entity except Exception as exp: print(exp) print(ex) if(indiaFlag): response = requests.get(url) if (response.status_code == 200): data = response.json() entity = entity if (entity == "World") else data['country'] entity = str(entity).title() entity = "**" + entity + "**" if(type=="All"): ccases = data['cases'] rcases = data['recovered'] dcases = data['deaths'] accases = data['active'] responeMsg = "Hey, the latest covid-19 cases of " + f"{entity}" + " with \n \n" + "Confirmed cases as " + f"{ccases}" + "\n \n" \ "and the Recovered Cases counts to " + f"{rcases}" + "\n \n" + "and finally the Death Cases are " + f"{dcases}" elif(type=="confirmed"): ccases = data['cases'] responeMsg = "The total confirmed covid-19 cases of " + f"{entity}" + " is " + f"{ccases}" elif (type == "deaths"): dcases = data['deaths'] responeMsg = "The total death cases of covid-19 in " + f"{entity}" + " is " + f"{dcases}" elif (type == "recovered"): rcases = data['recovered'] responeMsg = "The recovered cases for covid-19 in " + f"{entity}" + " is Recovered Cases " + f"{rcases}" if( 'countryInfo' in data): responeMsg+="$$$"+data['countryInfo']['flag'] else: responeMsg = "Sorry!! I could not reach the api.." except Exception as ex: print(ex) responeMsg = "Sorry!! I could not recognized you.." return responeMsg, ccases,rcases,dcases
('Lonely,Track,road Albany', 'North,Shore,City'), ('1102/30,Beach,Road City,Centre', 'Auckland,City'), ('Otara Otara', 'Manukau,City'), ('16,Burton,Street Grafton', 'Auckland,City'), ('304/184,Symonds,Street City,Centre', 'Auckland,City'), ('30/145,Quay,Street City,Centre', 'Auckland,City'), ('Maplesden Clendon,Park', 'Manukau,City'), ('152,Hobson,Street City,Centre', 'Auckland,City'), ('732,Massey,Road Mangere', 'Manukau,City'), ('Woodward Mount,Albert', ' Auckland,City'), ('1,courthouse,lane', 'City,Centre, Auckland,City'), ('507/2,Dockside,Lane', 'City,Centre, Auckland,City')] # key = 'ApfjtgVg2-JtMzi3b-sdJYnHNE6bpkRIdug30idpvaB-cF51TsA_BnppDBXRSujo' key = "" geolocator = Bing(key) f = open(r'Output\addCoordinates.txt', "w") loc = geolocator.geocode('10D/8 Scotia place, Auckland City , New Zealand') f.write('10D/8 Scotia place, Auckland City , New Zealand;' + str(loc.latitude) + ";" + str(loc.longitude) + "\n") print(loc.latitude, loc.longitude) for add in addresses: loc = geolocator.geocode(add[0] + ' ' + add[1] + ' New Zealand') f.write(add[0] + ' ' + add[1] + ' New Zealand;' + str(loc.latitude) + ";" + str(loc.longitude) + "\n") print(loc.latitude, loc.longitude) f.close()
def test_user_agent_custom(self): geocoder = Bing( api_key='DUMMYKEY1234', user_agent='my_user_agent/1.0' ) assert geocoder.headers['User-Agent'] == 'my_user_agent/1.0'