def clean(self): """ Validate set/validate mappable_location, longitude and latitude. """ super(EventLocation, self).clean() if self.lat and not self.lon: raise ValidationError("Longitude required if specifying latitude.") if self.lon and not self.lat: raise ValidationError("Latitude required if specifying longitude.") if not (self.lat and self.lon) and not self.mappable_location: self.mappable_location = self.address.replace("\n",", ") if self.mappable_location and not (self.lat and self.lon): #location should always override lat/long if set g = GoogleMaps(domain=settings.EVENT_GOOGLE_MAPS_DOMAIN) try: mappable_location, (lat, lon) = g.geocode(self.mappable_location.encode('utf-8')) except GQueryError as e: raise ValidationError("The mappable location you specified could not be found on {service}: \"{error}\" Try changing the mappable location, removing any business names, or leaving mappable location blank and using coordinates from getlatlon.com.".format(service="Google Maps", error=e.message)) except ValueError as e: raise ValidationError("The mappable location you specified could not be found on {service}: \"{error}\" Try changing the mappable location, removing any business names, or leaving mappable location blank and using coordinates from getlatlon.com.".format(service="Google Maps", error=e.message)) self.mappable_location = mappable_location self.lat = lat self.lon = lon
def trajectory_point_to_str(data, index, with_address=True): coords = "%s, %s" % tuple(data[index][1:]) if with_address: geocoder = Geocoder() address = geocoder.reverse(coords, exactly_one = True).address else: address = None tz = pytz.timezone('US/Pacific') date = num2date(data[index][0], tz=tz) try: dt = (num2date(data[index+1][0]) - date).total_seconds() dist = distance(data[index], data[index+1]) v = ms_to_mph*dist/dt if dt!=0 else 0 if dt < 60: dt_str = "%ds" % dt elif dt < 60*60: dt_str = "%dmin" % (dt/60,) else: dt_str = "%.1fh" % (dt/60/60,) metrics = "%s; %.2fm; %.fmph" % (dt_str, dist, v) except IndexError: metrics = "NO DATA" return "Index:%s; Date:%s; Address:%s; Coords: %s; dt,ds,v:%s" % \ (index, date, address, coords, metrics)
def clean(self): super(Event, self).clean() if self.lat and not self.lon: raise ValidationError(_("Longitude required if specifying latitude.")) if self.lon and not self.lat: raise ValidationError(_("Latitude required if specifying longitude.")) if not (self.lat and self.lon) and not self.mappable_location: self.mappable_location = self.location.replace("\n", ", ") if self.mappable_location: # location should always override lat/long if set g = GoogleMaps(domain=settings.MZEVENTS_GOOGLE_MAPS_DOMAIN) try: location, (lat, lon) = g.geocode(self.mappable_location.encode("utf-8")) except GQueryError as e: raise ValidationError( _( 'The mappable location you specified could not be found on {service}: "{error}" Try changing the mappable location, removing any business names, or leaving mappable location blank and using coordinates from getlatlon.com.' ).format(service="Google Maps", error=e.message) ) except ValueError as e: raise ValidationError( _( 'The mappable location you specified could not be found on {service}: "{error}" Try changing the mappable location, removing any business names, or leaving mappable location blank and using coordinates from getlatlon.com.' ).format(service="Google Maps", error=e.message) ) self.mappable_location = location self.lat = Decimal(str(lat)) self.lon = Decimal(str(lon))
def clean(self): super(Event, self).clean() if self.parent is None or not isinstance( self.parent.get_content_model(), Calendar): raise ValidationError("This event must belong to a Calendar.") if self.lat and not self.lon: raise ValidationError("Longitude required if specifying latitude.") if self.lon and not self.lat: raise ValidationError("Latitude required if specifying longitude.") if not (self.lat and self.lon) and not self.mappable_location: self.mappable_location = self.location.replace("\n",", ") if self.mappable_location: #location should always override lat/long if set g = GoogleMaps(domain=settings.MZEVENTS_GOOGLE_MAPS_DOMAIN) try: location, (lat, lon) = g.geocode(self.mappable_location.encode('utf-8')) except GQueryError as e: raise ValidationError("The mappable location you specified could not be found on {service}: \"{error}\" Try changing the mappable location, removing any business names, or leaving mappable location blank and using coordinates from getlatlon.com.".format(service="Google Maps", error=e.message)) except ValueError as e: raise ValidationError("The mappable location you specified could not be found on {service}: \"{error}\" Try changing the mappable location, removing any business names, or leaving mappable location blank and using coordinates from getlatlon.com.".format(service="Google Maps", error=e.message)) self.mappable_location = location self.lat = lat self.lon = lon
def clean(self): super(Event, self).clean() if not self.end_date: self.end_date = self.date if self.date > self.end_date: raise ValidationError("Start date must be sooner than end date.") if self.date == self.end_date and self.start_time > self.end_time: raise ValidationError("Start time must be sooner than end time.") if self.lat and not self.lon: raise ValidationError("Longitude required if specifying latitude.") if self.lon and not self.lat: raise ValidationError("Latitude required if specifying longitude.") location_to_geocode = self.mappable_location if not (self.lat and self.lon) and not self.mappable_location: location_to_geocode = self.location.replace("\n",", ") if self.mappable_location: #location should always override lat/long if set g = GoogleMaps(domain=settings.MZEVENTS_GOOGLE_MAPS_DOMAIN) try: location, (lat, lon) = g.geocode(location_to_geocode.encode('utf-8')) self.mappable_location = location_to_geocode self.lat = lat self.lon = lon except GQueryError as e: if(not not self.mappable_location): raise ValidationError("The mappable location you specified could not be found on {service}: \"{error}\" Try changing the mappable location, removing any business names, or leaving mappable location blank and using coordinates from getlatlon.com.".format(service="Google Maps", error=e)) except ValueError as e: if(not not self.mappable_location): raise ValidationError("The mappable location you specified could not be found on {service}: \"{error}\" Try changing the mappable location, removing any business names, or leaving mappable location blank and using coordinates from getlatlon.com.".format(service="Google Maps", error=e))
def find_address(address_text): g = GoogleV3() location = g.geocode(address_text) return [location.latitude,location.longitude]
import prov.model import datetime import uuid # Until a library is created, we just use the script directly. exec(open('../pymongo_dm.py').read()) # Set up the database connection. client = pymongo.MongoClient() repo = client.repo repo.authenticate('loyuichi', 'loyuichi') # Retrieve some data sets (not using the API here for the sake of simplicity). startTime = datetime.datetime.now() geolocator = GoogleV3() for meter in repo['loyuichi.meters'].find({ 'X': { '$exists': True }, 'Y': { '$exists': True } }): try: location = geolocator.reverse(str(meter['Y']) + ',' + str(meter['X'])) if (location): zipcode = location[0].raw['address_components'][-1]["long_name"] res = repo['loyuichi.meters'].update({'_id': meter['_id']},
def token(): content = request.json # kgp="Kharagpur" db = mysql.connect() cursor = db.cursor() print content if "callback_query" in content: chat_id = str(content['callback_query']['message']['chat']['id']) elif 'location' in content['message']: #.index(['location']) is not None: chat_id = content['message']['chat']['id'] elif 'text' in content['message']: chat_id = str(content['message']['chat']['id']) cursor.execute("select update_id from user where uid=%s", chat_id) update_id = cursor.fetchall() # print update_id[0][0] if cursor.rowcount == 0 or int(content['update_id']) > int( update_id[0][0]): updateid = content['update_id'] if "callback_query" in content: gans = content['callback_query']['data'] tcheck = content['callback_query']['message']['date'] cursor.execute("select qid from user where uid=%s", chat_id) i = cursor.fetchall() cursor.execute( "select qtime from userques where qid=%s and uid=%s", (i[0][0], chat_id)) qtime = cursor.fetchall() t = time.time() qt = t - qtime[0][0] cursor.execute( "update userques set qtime=%s where qid=%s and uid=%s", (qt, i[0][0], chat_id)) db.commit() db.close() if (t - int(tcheck)) > 30: bot.sendMessage( chat_id, "It seems your internet is not working properly. Don't worry your current status is saved :)" ) time.sleep(2) checkans(i, chat_id, gans) #print data #i=i+1 if i[0][0] == '5': reply_markup = ReplyKeyboardMarkup([[ telegram.KeyboardButton('Please share your location', request_location=True) ]], one_time_keyboard=True, resize_keyboard=True) bot.sendMessage( chat_id, 'Hey sorry for interrupting! Would you mind sharing your location just to compare you with other people near your area', reply_markup=reply_markup) else: takeques(int(i[0][0]) + 1, chat_id) elif 'location' in content[ 'message']: #.index(['location']) is not None: longi = content['message']['location']['longitude'] lati = content['message']['location']['latitude'] fname = content['message']['chat']['first_name'] # lname=content['message']['chat']['last_name'] name = fname geolocator = GoogleV3() location = geolocator.reverse((lati, longi)) #print location adduser(chat_id, 0, name, str(location[0]), updateid) cursor.execute("select qid from user where uid=%s", str(chat_id)) q = cursor.fetchall() if q[0][0] == 0: bot.sendMessage(chat_id, text="The quiz is about to start.") elif q[0][0] == 5: bot.sendMessage(chat_id, text="Continuing the same session of quiz... ") db.close() takeques(int(q[0][0]) + 1, chat_id) elif 'text' in content['message']: fname = content['message']['chat']['first_name'] # lname=content['message']['chat']['last_name'] name = fname msg = content['message']['text'] start(name, chat_id, msg, updateid) db.close() #db.close() return jsonify(content)
def login(self, provider, username, password): # login needs base class "create_request" self.useVanillaRequest = True # Get Timecode and Country Code country_code = "US" timezone = "America/Chicago" geolocator = GoogleV3(api_key=self.config.gmapkey) if self.config.locale_by_location: try: location = geolocator.reverse( (self.actual_lat, self.actual_lng), timeout=10, exactly_one=True) country_code = self.get_component(location, 'country') except: self.logger.warning( "Please make sure you have google api key and enable Google Maps Geocoding API at console.developers.google.com" ) try: timezone = geolocator.timezone( [self.actual_lat, self.actual_lng], timeout=10) except: self.logger.warning( "Please make sure you have google api key and enable Google Maps Time Zone API at console.developers.google.com" ) # Start login process try: if self.config.proxy: PGoApi.set_authentication(self, provider, username=username, password=password, proxy_config={ 'http': self.config.proxy, 'https': self.config.proxy }) else: PGoApi.set_authentication(self, provider, username=username, password=password) except: raise try: if self.config.locale_by_location: response = PGoApi.app_simulation_login(self, country_code, timezone.zone) else: response = PGoApi.app_simulation_login( self ) # To prevent user who have not update the api being caught off guard by errors except BadHashRequestException: self.logger.warning( "Your hashkey seems to have expired or is not accepted!") self.logger.warning( "Please set a valid hash key in your auth JSON file!") exit(-3) raise except BannedAccountException: self.logger.warning("This account is banned!") exit(-3) raise except: raise # cleanup code self.useVanillaRequest = False return response
import csv #Take in a Google kml location file and export a csv with date and addresses #should start with PYTHONIOENCODING=utf-8 and give it the inputfile as the argument #would love to be pointed to the more appropriate way to do this in python. #To invoke: #PYTHONIOENCODING=utf-8 python get_addresses.py input_file.kml #will produce input_file.kml.csv #note that this script does not make any attempt to do the rate limiting google expects #you should break your location data up into chunks that require less than 2500 calls #for example, by using the split utility #use your own key import location_config as cfg geolocator = GoogleV3(api_key=cfg.my_Google_api_key) #read the KML file kml_file = open(sys.argv[1], 'r') kml_text = kml_file.read() kml_file.close() #open the CSV output file outputfile = open((sys.argv[1] + '.csv'), "wb") writer = csv.writer(outputfile) count = 0 for when, where in re.findall( r'\<when\>(.+?)\<\/when\>\s+\<gx\:coord\>(.+?)\<\/gx\:coord\>', kml_text): #kml does longitude before latitude
def apartment_detail(request, id): try: num_user_reviews = 0 user = request.user apartment = Apartment.objects.get(id=id) units = Unit.objects.all() units = units.filter(apartment_name__icontains=apartment.name) data = serializers.serialize("json", [ apartment, ]) data_json = json.loads(data) # data_json = data_json[0]['fields']['location'] geolocator = GoogleV3( api_key="AIzaSyBnnca1doBE-nE14750VNFA4VtqlLrcJZk") lat = 0.0 lon = 0.0 loc = data_json[0]['fields']['location'] location = geolocator.geocode(data_json[0]['fields']['location']) try: lat = location.latitude lon = location.longitude except: lat = 0.0 lon = 0.0 if request.method == "POST": form = ReviewForm(request.POST) if form.is_valid(): post = form.save(commit=False) post.user = request.user post.apartment = apartment post.save() form = ReviewForm() return HttpResponseRedirect(request.path_info) return render( request, 'apartment_detail.html', { 'apartment': apartment, 'units': units, 'form': form, 'lat': lat, 'lon': lon, }) else: form = ReviewForm() reviews = Review.objects.all().filter(apartment=apartment) for review in reviews: if review.user == user: num_user_reviews = num_user_reviews + 1 return render( request, 'apartment_detail.html', { 'apartment': apartment, 'units': units, 'form': form, 'reviews': reviews, 'num_user_reviews': num_user_reviews, 'lat': lat, 'lon': lon }) except Apartment.DoesNotExist: raise Http404("Apartment not found")
# from geopy.geocoders import Nominatim from geopy.geocoders import GoogleV3 from geopy.distance import geodesic import googlemaps from datetime import datetime import pandas as pd import urllib.request import json import pprint import config # geolocator = Nominatim(user_agent="specify_your_app_name_here") geolocator = GoogleV3(api_key=config.api_key) gmaps = googlemaps.Client(key=config.maps_api_key) tigray = [ 'Himora', 'Shire', 'Aksum', 'Adwa', 'Adigrat', 'Negash', 'Mekele', 'Ambalage', 'Korem', 'Alamta', 'Shiraro', 'Birkuta', 'Adi Ramets', 'Inda Aba Guna', 'Slehleka', 'Rama', 'Zufan', 'Enticho', 'Freweyni', 'Wikro', 'Nebelet', 'May Tsemre', 'Abiy Addi', 'Yechilay', 'Maychew', 'Hiwane', 'Sheraro', 'Hidmo' ] amhara = [ 'Weldiya', 'Mersa', 'Dessie', 'Kombolcha', 'Senbete', 'Molale', 'Ankober', 'Debre Birhan', 'Rema', 'Mertule Maryam', 'Felege Birhan', 'Zebich', 'Dejen', 'Debre Markos', 'Dembecha', 'Bure', 'Injibara', 'Dangla', 'Durbete', 'Mer Awi', 'Bahir Dar', 'Addis Zemen', 'Gondar', 'Amba Giorgis', 'Dabat', 'Debark', 'Chew Ber', 'Amdework', 'Sekota', 'Lalibela', 'Gashena', 'Wegel Tena', 'Tenta', 'Akesta', 'Metema', 'Shawira', 'Shewa Robit', 'Nefas Meewcha', 'Debre Tabor', 'Mekane Selam', 'Deneba', 'Motta', 'Sheba',
def preprocessing(): user_dict = {} if os.path.isfile("./users/proc_user_dict.txt"): with open("./users/proc_user_dict.txt", "r", encoding="utf8") as f: user_dict = eval(f.read()) else: for file in os.listdir("./users/"): if "proc" not in file: with open("./users/" + file, "r", encoding="utf8") as f: for line in tqdm(f.readlines()): line_array = line.split("\t") username = line_array[0].strip() repos_url = line_array[1].strip() location = line_array[2].strip() avatar_url = line_array[3].strip() public_repos = line_array[4].strip() name = line_array[5].strip() if os.path.isfile("./proc_images/" + username + ".jpg"): if location != "" and location is not None: print(location) geolocator = GoogleV3( api_key= "AIzaSyDD9bAmgJQYnqnCM6v-kRtl4hTWIHdaVac") try: location_result = geolocator.geocode( location.replace(" ", "%20")) if location_result is not None: country = None for component in location_result.raw[ "address_components"]: if "country" in component["types"]: country = component[ "long_name"] if country is not None: temp_user = { "username": username, "repos_url": repos_url, "location": location, "avatar_url": avatar_url, "public_repos": public_repos, "name": name, "country": country } user_dict[username] = temp_user with open( "./users/proc_user_dict.txt", "w", encoding="utf8") as f: f.write(str(user_dict)) except geopy.exc.GeocoderTimedOut: pass time.sleep(1) # Face data arranged by user. face_dict = {} with open("./faces/faces.txt", "r", encoding="utf8") as f: face_dict = eval(f.read()) # Set up output dictionary. user_order = [] output = {} output_array = [] output_df = pd.DataFrame(columns=[ "gender", "age", "moustache", "sideburns", "beard", "bald", "black_hair_color", "brown_hair_color", "other_hair_color", "gray_hair_color", "red_hair_color", "blond_hair_color", "country" ]) for i, (user, sub_dict) in enumerate(user_dict.items()): if user in face_dict: if len(face_dict[user]) == 1: user_face = face_dict[user][0] gender = user_face["faceAttributes"]["gender"] age = user_face["faceAttributes"]["age"] moustache = user_face["faceAttributes"]["facialHair"][ "moustache"] sideburns = user_face["faceAttributes"]["facialHair"][ "sideburns"] beard = user_face["faceAttributes"]["facialHair"]["beard"] bald = user_face["faceAttributes"]["hair"]["bald"] black_hair_color = 0 brown_hair_color = 0 other_hair_color = 0 gray_hair_color = 0 red_hair_color = 0 blond_hair_color = 0 country = sub_dict["country"] for hair_color in user_face["faceAttributes"]["hair"][ "hairColor"]: if hair_color["color"] == "black": black_hair_color = hair_color["confidence"] elif hair_color["color"] == "brown": brown_hair_color = hair_color["confidence"] elif hair_color["color"] == "other": other_hair_color = hair_color["confidence"] elif hair_color["color"] == "gray": gray_hair_color = hair_color["confidence"] elif hair_color["color"] == "red": red_hair_color = hair_color["confidence"] elif hair_color["color"] == "blond": blond_hair_color = hair_color["confidence"] user_order.append(user) output[user] = [ gender, age, moustache, sideburns, beard, bald, black_hair_color, brown_hair_color, other_hair_color, gray_hair_color, red_hair_color, blond_hair_color, country ] output_array.append([ gender, age, moustache, sideburns, beard, bald, black_hair_color, brown_hair_color, other_hair_color, gray_hair_color, red_hair_color, blond_hair_color, country ]) output_df.loc[i] = output[user] # Change gender and country into numeric variables. output_df["gender"] = output_df["gender"].astype("category") output_df["country"] = output_df["country"].astype("category") cat_columns = output_df.select_dtypes(["category"]).columns output_df.to_csv("./categories/output.csv") output_df[cat_columns] = output_df[cat_columns].apply( lambda x: x.cat.codes) output_df.to_csv("./categories/output_encoded.csv") # Set up input dataframe. input_df = pd.DataFrame(columns=[ "mean_lines", "mean_chars", "mean_words", "mean_spaces", "mean_tabs", "median_lines", "median_chars", "median_words", "median_spaces", "median_tabs", "c", "cplusplus", "csharp", "delphiobjectpascal", "go", "java", "javascript", "objectivec", "perl", "php", "plsql", "python", "r", "ruby", "scala", "shell", "sql", "swift", "typescript", "visualbasicnet", "af", "ar", "bg", "bn", "ca", "cs", "cy", "da", "de", "el", "en", "es", "et", "fa", "fi", "fr", "gu", "he", "hi", "hr", "hu", "id", "it", "ja", "kn", "ko", "lt", "lv", "mk", "ml", "mr", "ne", "nl", "no", "pa", "pl", "pt", "ro", "ru", "sk", "sl", "so", "sq", "sv", "sw", "ta", "te", "th", "tl", "tr", "uk", "ur", "vi", "zh_cn", "zh_tw" ]) ## Keyword counts arranged by user and file. #file_keyword_distributions = {} #with open("./keywords/distributions/keywords.txt", "r", encoding="utf8") as f: # file_keyword_distributions = eval(f.read()) # Metrics metric_dict = {} with open("./metrics/median.txt", "r", encoding="utf8") as f: metric_dict = eval(f.read()) # Natural languages. nat_lang_dict = {} with open("./nat_lang/nat_lang.txt", "r", encoding="utf8") as f: nat_lang_dict = eval(f.read()) # Programming languages. prog_lang_dict = {} with open("./prog_lang/lang_dict.txt", "r", encoding="utf8") as f: prog_lang_dict = eval(f.read()) for i, user in enumerate(user_order): user_stats = metric_dict[user]["user_stats"] prog_lang_counts = prog_lang_dict[user]["language_dictionary"] c = prog_lang_counts["c"] if "c" in prog_lang_counts else 0 cplusplus = prog_lang_counts[ "cplusplus"] if "cplusplus" in prog_lang_counts else 0 csharp = prog_lang_counts[ "csharp"] if "csharp" in prog_lang_counts else 0 delphiobjectpascal = prog_lang_counts[ "delphiobjectpascal"] if "delphiobjectpascal" in prog_lang_counts else 0 go = prog_lang_counts["go"] if "go" in prog_lang_counts else 0 java = prog_lang_counts["java"] if "java" in prog_lang_counts else 0 javascript = prog_lang_counts[ "javascript"] if "javascript" in prog_lang_counts else 0 objectivec = prog_lang_counts[ "objectivec"] if "objectivec" in prog_lang_counts else 0 perl = prog_lang_counts["perl"] if "perl" in prog_lang_counts else 0 php = prog_lang_counts["php"] if "php" in prog_lang_counts else 0 plsql = prog_lang_counts["plsql"] if "plsql" in prog_lang_counts else 0 python = prog_lang_counts[ "python"] if "python" in prog_lang_counts else 0 r = prog_lang_counts["r"] if "r" in prog_lang_counts else 0 ruby = prog_lang_counts["ruby"] if "ruby" in prog_lang_counts else 0 scala = prog_lang_counts["scala"] if "scala" in prog_lang_counts else 0 shell = prog_lang_counts["shell"] if "shell" in prog_lang_counts else 0 sql = prog_lang_counts["sql"] if "sql" in prog_lang_counts else 0 swift = prog_lang_counts["swift"] if "swift" in prog_lang_counts else 0 typescript = prog_lang_counts[ "typescript"] if "typescript" in prog_lang_counts else 0 visualbasicnet = prog_lang_counts[ "visualbasicnet"] if "visualbasicnet" in prog_lang_counts else 0 af = 0 ar = 0 bg = 0 bn = 0 ca = 0 cs = 0 cy = 0 da = 0 de = 0 el = 0 en = 0 es = 0 et = 0 fa = 0 fi = 0 fr = 0 gu = 0 he = 0 hi = 0 hr = 0 hu = 0 id = 0 it = 0 ja = 0 kn = 0 ko = 0 lt = 0 lv = 0 mk = 0 ml = 0 mr = 0 ne = 0 nl = 0 no = 0 pa = 0 pl = 0 pt = 0 ro = 0 ru = 0 sk = 0 sl = 0 so = 0 sq = 0 sv = 0 sw = 0 ta = 0 te = 0 th = 0 tl = 0 tr = 0 uk = 0 ur = 0 vi = 0 zh_cn = 0 zh_tw = 0 file_list = [] for sub_key, sub_val in nat_lang_dict[user].items(): file_list.append(sub_key) for infra_key, infra_val in sub_val.items(): lang_code = infra_key confidence = infra_val if lang_code == "af": af += confidence elif lang_code == "ar": ar += confidence elif lang_code == "bg": bg += confidence elif lang_code == "bn": bn += confidence elif lang_code == "ca": ca += confidence elif lang_code == "cs": cs += confidence elif lang_code == "cy": cy += confidence elif lang_code == "da": da += confidence elif lang_code == "de": de += confidence elif lang_code == "el": el += confidence elif lang_code == "en": en += confidence elif lang_code == "es": es += confidence elif lang_code == "et": et += confidence elif lang_code == "fa": fa += confidence elif lang_code == "fi": fi += confidence elif lang_code == "fr": fr += confidence elif lang_code == "gu": gu += confidence elif lang_code == "he": he += confidence elif lang_code == "hi": hi += confidence elif lang_code == "hr": hr += confidence elif lang_code == "hu": hu += confidence elif lang_code == "id": id += confidence elif lang_code == "it": it += confidence elif lang_code == "ja": ja += confidence elif lang_code == "kn": kn += confidence elif lang_code == "ko": ko += confidence elif lang_code == "lt": lt += confidence elif lang_code == "lv": lv += confidence elif lang_code == "mk": mk += confidence elif lang_code == "ml": ml += confidence elif lang_code == "mr": mr += confidence elif lang_code == "ne": ne += confidence elif lang_code == "nl": nl += confidence elif lang_code == "no": no += confidence elif lang_code == "pa": pa += confidence elif lang_code == "pl": pl += confidence elif lang_code == "pt": pt += confidence elif lang_code == "ro": ro += confidence elif lang_code == "ru": ru += confidence elif lang_code == "sk": sk += confidence elif lang_code == "sl": sl += confidence elif lang_code == "so": so += confidence elif lang_code == "sq": sq += confidence elif lang_code == "sv": sv += confidence elif lang_code == "sw": sw += confidence elif lang_code == "ta": ta += confidence elif lang_code == "te": te += confidence elif lang_code == "th": th += confidence elif lang_code == "tl": tl += confidence elif lang_code == "tr": tr += confidence elif lang_code == "uk": uk += confidence elif lang_code == "ur": ur += confidence elif lang_code == "vi": vi += confidence if len(file_list) > 0: af = af / len(file_list) ar = ar / len(file_list) bg = bg / len(file_list) bn = bn / len(file_list) ca = ca / len(file_list) cs = cs / len(file_list) cy = cy / len(file_list) da = da / len(file_list) de = de / len(file_list) el = el / len(file_list) en = en / len(file_list) es = es / len(file_list) et = et / len(file_list) fa = fa / len(file_list) fi = fi / len(file_list) fr = fr / len(file_list) gu = gu / len(file_list) he = he / len(file_list) hi = hi / len(file_list) hr = hr / len(file_list) hu = hu / len(file_list) id = id / len(file_list) it = it / len(file_list) ja = ja / len(file_list) kn = kn / len(file_list) ko = ko / len(file_list) lt = lt / len(file_list) lv = lv / len(file_list) mk = mk / len(file_list) ml = ml / len(file_list) mr = mr / len(file_list) ne = ne / len(file_list) nl = nl / len(file_list) no = no / len(file_list) pa = pa / len(file_list) pl = pl / len(file_list) pt = pt / len(file_list) ro = ro / len(file_list) ru = ru / len(file_list) sk = sk / len(file_list) sl = sl / len(file_list) so = so / len(file_list) sq = sq / len(file_list) sv = sv / len(file_list) sw = sw / len(file_list) ta = ta / len(file_list) te = te / len(file_list) th = th / len(file_list) tl = tl / len(file_list) tr = tr / len(file_list) uk = uk / len(file_list) ur = ur / len(file_list) vi = vi / len(file_list) zh_cn = zh_cn / len(file_list) zh_tw = zh_tw / len(file_list) input_df.loc[i] = [ user_stats["mean_lines"], user_stats["mean_chars"], user_stats["mean_words"], user_stats["mean_spaces"], user_stats["mean_tabs"], user_stats["median_lines"], user_stats["median_chars"], user_stats["median_words"], user_stats["median_spaces"], user_stats["median_tabs"], c, cplusplus, csharp, delphiobjectpascal, go, java, javascript, objectivec, perl, php, plsql, python, r, ruby, scala, shell, sql, swift, typescript, visualbasicnet, af, ar, bg, bn, ca, cs, cy, da, de, el, en, es, et, fa, fi, fr, gu, he, hi, hr, hu, id, it, ja, kn, ko, lt, lv, mk, ml, mr, ne, nl, no, pa, pl, pt, ro, ru, sk, sl, so, sq, sv, sw, ta, te, th, tl, tr, uk, ur, vi, zh_cn, zh_tw ] return input_df, output_df
def test_user_agent_custom(self): geocoder = GoogleV3(user_agent='my_user_agent/1.0') self.assertEqual(geocoder.headers['User-Agent'], 'my_user_agent/1.0')
def setUpClass(cls): cls.geocoder = GoogleV3() cls.new_york_point = Point(40.75376406311989, -73.98489005863667) cls.america_new_york = timezone("America/New_York")
def get_pos_by_name(location_name): geolocator = GoogleV3() loc = geolocator.geocode(location_name) if not loc: return None return (loc.latitude, loc.longitude, loc.altitude)
def latlongi(request): print("Hello from latlongi") if request.method == "POST": latitude = request.POST['latitude'] longitude = request.POST['longitude'] print("Hello from latlongi", latitude, longitude) # idhar apoorva ka code aayega to fnd pincode from geopy.geocoders import GoogleV3 geolocator = GoogleV3(api_key='') latlong = latitude + ',' + longitude locations = geolocator.reverse(latlong) if locations: i = locations[0].address.rfind(',') print(" sdfghgf", locations[0].address) print(locations[0].address[i - 6:i]) pincode = str(locations[0].address[i - 6:i]) currentuserrid = request.session['email'] hospitaltype = "Maternity" data = db.child('Pincode').child(pincode).get().val() k = 0 # print(data) databaseuser = db.child('users').get().val() for i in data: print(i) hospital = str( db.child('Pincode').child(pincode).child(i).child( 'type').get().val()).split(',') print(hospital) for j in hospital: print("From j", j) if j == hospitaltype: print("Hospital Mil-Gaya") k = 1 for l in databaseuser: if str( db.child('users').child(l).child( 'email').get().val()) == currentuserrid: hospitalemail = str( db.child('Pincode').child(pincode).child( i).child('email').get().val()) emargencyemail = db.child('users').child(l).child( 'emergencyemail').get().val() CurrentAddress = "Rahul Soni 123." print(l) Address = str( db.child('users').child(l).child( 'name').get().val() ) + " is not feeling comfortable. Please look after him ASAP." print(Address) email_from = settings.EMAIL_HOST_USER subject = "Emergency Found" recipient_list = [] recipient_list.append(hospitalemail) recipient_list.append(emargencyemail) send_mail(subject, Address, email_from, recipient_list, fail_silently=False) print("Message Sent") break # send email to hospital break if k == 1: break if k == 0: databaseuser = db.child('users').get().val() for i in data: for j in databaseuser: if db.child('users').child(j).child( 'email').get().val() == currentuserrid: print(i) print("Hospital Nahi mila ") print( db.child('Pincode').child(pincode).child(i).child( 'email').get().val()) print( db.child('Pincode').child(pincode).child(i).child( 'contactno').get().val()) hospitalemail = str( db.child('Pincode').child(pincode).child(i).child( 'email').get().val()) emargencyemail = db.child('users').child(j).child( 'emergencyemail').get().val() print("Hospital Email ", hospitalemail) print("Emergency Email ", emargencyemail) CurrentAddress = "Rahul Soni 123." print( db.child('users').child(j).child( 'name').get().val()) Address = db.child('users').child(j).child('name').get( ).val( ) + "is not feeling comfortable. Please look after him ASAP." email_from = settings.EMAIL_HOST_USER subject = "Emergency Found" recipient_list = [] recipient_list.append(hospitalemail) recipient_list.append(emargencyemail) # hospital =str(db.child(pincode).child(i).child('type').get().val()).split(',') send_mail(subject, Address, email_from, recipient_list, fail_silently=False) break break users = db.child('users').child('7g6ZdpFJDIbUwBk2S7NbkaPDh9o2') # feeddata = { # "VictimId":currentuserrid, # "pincode":"400060", # "HospitalCalled":"NanavtiHospital" # } # p = db2.child('Feeds').push(feeddata) print(users) print( db.child('users').child('7g6ZdpFJDIbUwBk2S7NbkaPDh9o2').child( 'emergencycontactname').get().val()) print( db.child('users').child('7g6ZdpFJDIbUwBk2S7NbkaPDh9o2').child( 'emergencycontactname').get().val()) print("Message Sent To ") return HttpResponse("DOne")
import json import time from geopy.geocoders import GoogleV3, Nominatim # from models import Document, Requestor def get_secrets(): with open("apikey.txt") as f: return [l.strip() for l in f.readlines()] (API_KEY, URL, SHEET_ID) = get_secrets() API_KEY = open("apikey.txt").read().strip() goog_geolocator = GoogleV3(API_KEY) JSON_NAME = "entries.json" # If modifying these scopes, delete the file token.json. SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly'] # The ID and range of a sample spreadsheet. RANGE = "Restaurants!A:I" def build_service(): creds = None # The file token.json stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. if os.path.exists('token.json'):
# -*- coding: utf-8 -*- """ Created on Fri Feb 15 11:49:30 2021 @author: lduan """ from facebook_scraper import get_posts from geopy.geocoders import GoogleV3 import re import pandas as pd from pymongo import MongoClient loc_lat = [] loc_long = [] date = [] geolocator = GoogleV3(api_key="AIzaSyC10O0_UrRTtFJOdYo4VfuloSVk7zVbaV0") for post in get_posts('Windsorfirefighters', pages=100): if re.search(r'(\d+) block of', post['text'], re.M | re.I) or re.search( r'(\d+) (\S+) St', post['text'], re.M | re.I) or re.search( r'(\d+) (\S+) Blvd', post['text'], re.M | re.I) or re.search( r'(\d+) (\S+) Dr', post['text'], re.M | re.I) or re.search( r'(\d+) (\S+) Crt', post['text'], re.M | re.I) or re.search( r'(\d+) (\S+) Cir', post['text'], re.M | re.I): clean_posts = re.sub('(http\S+)', '', post['text']).strip().replace('\n', '') loc_extract = [ tuple(i for i in record if i) for record in re.findall( r'((\d+) block of (\S+) (\S+))|((\d+) (\S+) St)|((\d+) (\S+) Blvd)|((\d+) (\S+) Dr)|((\d+) (\S+) Crt)', post['text'], re.M | re.I) ]
def _geocodeScript(request, context): api_selection = None resultList = [] idNumList = [] # counter z = 1 # Iterate over bundled rows for request_rows in request: # Iterate over rows for row in request_rows.rows: logging.info('Geocoding address # ' + str(z)) z += 1 # The first strData is the coordinate data = [d.strData for d in row.duals][0] # grab the id idNum = [d.numData for d in row.duals][1] idNumList.append(idNum) # Grab selected API # Possible choices are: Google, Open Street, GeocoderDotUS if not api_selection: api_selection = [d.strData for d in row.duals][2] if 'google' in api_selection.lower(): geolocator = GoogleV3() elif 'open street' in api_selection.lower(): geolocator = Nominatim(scheme='http') elif 'geocoderdotus' in api_selection.lower(): geolocator = GeocoderDotUS() else: geolocator = Nominatim() # geocode for i in range(2): try: location = geolocator.geocode(data, timeout=2) break except geopy.exc.GeocoderTimedOut: pass except geopy.exc.GeocoderQueryError: pass except urllib.error.HTTPError: pass try: latitude = location.latitude except AttributeError: latitude = 'Unavailable' try: longitude = location.longitude except AttributeError: longitude = 'Unavailable' coordinates = '[' + str(longitude) + ', ' + str(latitude) + ']' resultList.append(coordinates) # Create an iterable of dual with the result dualsList = [] dualsList.append([SSE.Dual(numData=d) for d in idNumList]) dualsList.append([SSE.Dual(strData=d) for d in resultList]) response_rows = [] for i in range(len(idNumList)): duals = [dualsList[z][i] for z in range(len(dualsList))] response_rows.append(SSE.Row(duals=iter(duals))) # Set and send Table header table = SSE.TableDescription(name='Geocodes') table.fields.add(dataType=SSE.NUMERIC) table.fields.add(dataType=SSE.STRING) md = (('qlik-tabledescription-bin', table.SerializeToString()), ) context.send_initial_metadata(md) yield SSE.BundledRows(rows=response_rows)
def apartments(request): search_term = '' apartments_list = Apartment.objects.all() priceFilter = request.GET.get('sortInput', 'No Sort') if 'sortInput' in request.GET: priceFilter = request.GET['sortInput'] if "Low to High" == priceFilter: apartments_list = Apartment.objects.order_by('minPrice') elif "High to Low" == priceFilter: apartments_list = Apartment.objects.order_by('-maxPrice') if 'search' in request.GET: search_term = request.GET['search'] apartments_list = apartments_list.filter(name__icontains=search_term) maxPriceInput = request.GET.get('max_price_input', '3500') if 'max_price_input' in request.GET: maxPriceInput = request.GET['max_price_input'] apartments_list = apartments_list.filter(minPrice__lte=maxPriceInput) """ for apt in apartments: aptprice = getattr(apt, "price") if "-" in aptprice: aptprice = aptprice.split("-")[1] if "–" in aptprice: # this looks like a hyphen but is not. This is not duplicate code aptprice = aptprice.split("–")[1] aptprice = aptprice.replace("-","").replace(",","").replace("$","").strip() if int(aptprice) > int(maxPriceInput): aptname = getattr(apt, "name") apartments = apartments.filter(name__icontains=aptname) """ bedroomInput = request.GET.get('bedroomInput', 'No Filter') if 'bedroomInput' in request.GET: bedroomInput = request.GET['bedroomInput'] if bedroomInput != "None" and bedroomInput != "No Filter" and bedroomInput != "No": apartments_list = apartments_list.filter(maxBR__gte=bedroomInput) ratingInput = request.GET.get('ratingInput', 'No Sort') if 'ratingInput' in request.GET: ratingInput = request.GET['ratingInput'] if "High to Low" == ratingInput: apartments_list = apartments_list.filter( ratings__isnull=False).order_by('-ratings__average') elif "Low to High" == ratingInput: apartments_list = apartments_list.filter( ratings__isnull=False).order_by('ratings__average') compare0 = None compare1 = None if not request.user.is_anonymous: user_profile = UserProfile.objects.get(user=request.user) if user_profile.compare0: compare0 = user_profile.compare0 if user_profile.compare1: compare1 = user_profile.compare1 paginator = Paginator(apartments_list, 10) # Show 25 apartments per page page = request.GET.get('page') apartments = paginator.get_page(page) data = serializers.serialize("json", apartments) data_json = json.loads(data) geolocator = GoogleV3(api_key="AIzaSyBnnca1doBE-nE14750VNFA4VtqlLrcJZk") apartments_urls = [] apartments_pks = [] apartments_locations = [] apartments_names = [] apartments_images = [] lats = [] lons = [] apartments_prices = [] for i in range(0, len(apartments)): apartments_urls.append( reverse('apartment_detail', args=[data_json[i]['pk']])) apartments_pks.append(data_json[i]['pk']) apartments_locations.append(data_json[i]['fields']['location']) apartments_names.append(data_json[i]['fields']['name']) apartments_images.append(data_json[i]['fields']['image']) apartments_prices.append(data_json[i]['fields']['price']) try: location = geolocator.geocode(data_json[i]['fields']['location']) lats.append(location.latitude) lons.append(location.longitude) except: lons.append(0.00) lats.append(0.00) len_apartments = len(apartments) return render( request, 'apartments.html', { 'apartments': apartments, 'priceSort': priceFilter, 'maxPriceInput': maxPriceInput, 'bedroomInput': bedroomInput, 'ratingInput': ratingInput, 'compare0': compare0, 'compare1': compare1, 'apartments_pks': apartments_pks, 'apartments_locations': apartments_locations, 'lats': lats, 'lons': lons, 'len_apartments': len_apartments, 'apartments_names': apartments_names, 'apartments_images': apartments_images, 'apartments_prices': apartments_prices })
# -*- coding: utf-8 -*- import pandas as pd import pickle from geopy.geocoders import GoogleV3 geolocator = GoogleV3(api_key='Google API Key') with open('geolocations.pkl', 'rb') as f: data = pickle.load(f) print(data) users_with_countries = { "data": [] } tweets = 0 for itemdata in data['data']: print (itemdata['features']['location']) tweets = tweets + 1 try: location = itemdata['features']['location'] if location != None: location = geolocator.geocode(location) print((location.latitude, location.longitude)) print(tweets) user_data = { "user_id" : tweets,
def get_place(coords): geolocator = GoogleV3() return geolocator.reverse(coords)[0][0]
def parse_Geoposition(location, zipcode='', country='', use_saved_locations=False): """ Nominatim request for the Geoposition of a specific location in a country. Returns a tuples with (latitude, longitude, country) if the request was sucessful, returns np.nan otherwise. ToDo: There exist further online sources for lat/long data which could be used, if this one fails, e.g. - Google Geocoding API - Yahoo! Placefinder - https://askgeo.com (??) Parameters ---------- location : string description of the location, can be city, area etc. country : string name of the country which will be used as a bounding area use_saved_postion : Boolean, default False Whether to firstly compare with cached results in powerplantmatching/data/parsed_locations.csv """ from geopy.geocoders import GoogleV3 # ArcGIS Yandex Nominatim import geopy.exc if location is None or location == float: return np.nan countries = [(c, country_alpha_2(c)) for c in to_list_if_other(country)] for country, country_abbr in countries: if use_saved_locations: saved = pd.read_csv(_data('parsed_locations.csv'), index_col=[0, 1], encoding='utf-8') if saved.index.contains((location, country)): return [ saved.at[(location, country), 'lat'], saved.at[(location, country), 'lon'], country ] try: gdata = (GoogleV3(api_key=get_config()['google_api_key'], timeout=10).geocode(query=location, components={ 'country': country_abbr, 'postal_code': str(zipcode) }, exactly_one=True)) except geopy.exc.GeocoderQueryError as e: logger.warn(e) return np.nan if gdata is None: continue if ',' not in gdata.address: continue values = [ gdata.latitude, gdata.longitude, gdata.address.split(', ')[-1] ] if use_saved_locations: (pd.DataFrame(dict(zip(['lat', 'lon', 'Country'], values)), index=[location ]).to_csv(_data('parsed_locations.csv'), header=False, mode='a', encoding='utf-8')) return values return np.nan
import requests import re from geopy.geocoders import GoogleV3 from geopy.distance import vincenty geolocator = GoogleV3(api_key='AIzaSyDBZre20-q9hSY0BFXTqmiZr5-orJSuwr0') def returnLatLong(busNumber): res = requests.get( 'https://catbus.transloc.com/m/feeds/vehicles/{}'.format(busNumber)) string = str(res.text) a = string.partition('lat="')[2].partition('"')[0] b = string.partition('lng="')[2].partition('"')[0] return (a, b) def convertLatLong(address): a = geolocator.geocode(address) return (a.latitude, a.longitude) def createResponse(busNumber, distance=0, oos=False, location=None): if oos == True: return { "version": "1.0", "sessionAttributes": {}, "response": { "outputSpeech": { "type": "PlainText", "text":
from geopy.geocoders import GoogleV3 myApi = 'AIzaSyBAPR_JscpDtaLzmvYV-oAZGQAEp8kxBic' geolocator = GoogleV3(api_key=myApi) location = geolocator.geocode(query=search_blog_keyword, language='ko', exactly_one=False, timeout=5) print(location[0].latitude, location[0].longitude)
from geopy.geocoders import GoogleV3 from Dicc_Tipo_Danhos import camb_tipos import tqdm try: import argparse flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args() except ImportError: flags = None # If modifying these scopes, delete your previously saved credentials # at ~/.credentials/sheets.googleapis.com-python-quickstart.json SCOPES = 'https://www.googleapis.com/auth/spreadsheets.readonly' CLIENT_SECRET_FILE = 'creds/secreto_cliente.json' APPLICATION_NAME = 'Temblor' geolocator = GoogleV3(api_key=os.environ.get('GM_KEY')) # Dirección debe ser de la forma "Num Calle Ciudad" def dir_correct(calle, numero): k = [] k.append(numero) k.append(calle) k.append('cdmx') dirr = ' '.join(k) return dirr def obtain_latlong(dirr): try: location = geolocator.geocode(dirr)
def make_geocoder(cls, **kwargs): return GoogleV3(api_key=env['GOOGLE_KEY'], **kwargs)
# import the geocoding services you'd like to try # sourced at https://gist.github.com/rgdonohue/c4beedd3ca47d29aef01 from geopy.geocoders import ArcGIS, Bing, Nominatim, OpenCage, GeocoderDotUS, GoogleV3, OpenMapQuest import csv, sys print('creating geocoding objects!') arcgis = ArcGIS(timeout=100) bing = Bing('EskjSss5VoskMkVH9455~Mw_sz22GdAR8PAJf_yOcRw~Ak7zshEQvx8HunHbrUjh7l9PsVYxVjAMd9q-2R3cNm9L4J8IQeqt4meCt-1esehh',timeout=100) nominatim = Nominatim(timeout=100) opencage = OpenCage('f579fc0ccbf975c8d822196eca92cf64',timeout=100) googlev3 = GoogleV3(timeout=100) openmapquest = OpenMapQuest(timeout=100) # choose and order your preference for geocoders here geocoders = [googlev3, bing, nominatim, arcgis, opencage, openmapquest] def geocode(address): i = 0 try: while i < len(geocoders): # try to geocode using a service location = geocoders[i].geocode(address) # if it returns a location if location != None: # return those values return [location.latitude, location.longitude] else:
async def test_user_agent_custom(self): geocoder = GoogleV3(api_key='mock', user_agent='my_user_agent/1.0') assert geocoder.headers['User-Agent'] == 'my_user_agent/1.0'
def geocode( sender, instance, **kwargs ): if instance.location: g = Geo() location = g.geocode( instance.location ) instance.latitude = location.latitude instance.longitude = location.longitude
async def test_configuration_error(self): with pytest.raises(exc.ConfigurationError): GoogleV3(api_key='mock', client_id='a') with pytest.raises(exc.ConfigurationError): GoogleV3(api_key='mock', secret_key='a')
from geopy.geocoders import GoogleV3 # key generated from the Google APIs console # https://code.google.com/apis/console/?noredirect api_key = 'AIzaSyDsQ_qGhhwpcPZJlCSNTHEfzsLoxagRDGo' # instantiate GoogleV3 objet gmaps = GoogleV3(api_key) # latitude and longitude from address address = '6363 Christie Ave. Emeryville, CA' loc1 = gmaps.geocode(address) print loc1.latitude, loc1.longitude # reverse -- address from coordinates coords = (loc1.latitude, loc1.longitude) loc2 = gmaps.reverse(coords) print loc2[0].address
async def test_no_error_with_no_api_key_but_using_premier(self): GoogleV3(client_id='client_id', secret_key='secret_key')
async def test_error_with_no_api_key(self): with pytest.raises(exc.ConfigurationError): GoogleV3()
from geopy.geocoders import GoogleV3 fname_adresses = ["addresses.txt","stops.txt","starts.txt"] fname_adressesOut = ["addressesOut.txt","stopsOut.txt","startsOut.txt"] for idx, val in enumerate(fname_adresses): outFile = open(fname_adressesOut[idx],"w") with open(fname_adresses[idx]) as f: content = f.readlines() for address in content: print address; if address == "\n": outFile.write("\n"); else: geolocator = GoogleV3(api_key = "AIzaSyBirONocHuXh5un_iDZVLfE_pg6c6vv4EQ", timeout = None) location = geolocator.geocode(address + ", Canada") if location != None: latitude = location.latitude longitude = location.longitude address = str(location.raw['address_components'][0]['short_name']) + " " + str(location.raw['address_components'][1]['short_name']); outFile.write(str(latitude) + "," + str(longitude) + "=" + address + "\n"); print latitude print longitude outFile.close();