#!/usr/bin/env python # coding: utf-8 # In[2]: import numpy as np, pandas as pd geoco import time import json import matplotlib.pyplot as plt get_ipython().run_line_magic('matplotlib', 'inline') import warnings warnings.filterwarnings("ignore") # In[3]: #load cities varosok=[ 'csikszereda', 'udvarhely', 'szentgyorgy', 'vasarhely', 'barot', 'gyergyo', 'kezdi', 'keresztur', 'kovaszna', 'balan', 'vlahica', 'parajd', 'szovata', 'regen', 'kolozsvar', 'segesvar', 'toplita'] varos=varosok[0] varos # In[3]: #global array of people harvested GP=[] for path in {"db/","db2/"}: for varos in varosok: lines = [line.rstrip('\n') for line in open(path+varos+'.txt')] L=[i for i in lines if ((i!='') and (i!='..'))] #set start of friend list for i in range(len(L)): if 'FriendFriends' in L[i]: break if 'Add Friend' in L[i]: break L=L[i:] #set end of friend list c=0 for i in range(len(L)): if 'FriendFriends' in L[i]: c=i if 'Add Friend' in L[i]: c=i L=L[:c+8] #from here people entries are separated by a dot line #store people in array T T=[] subL=[] for l in L: if l!='.': if l!='FriendFriends': if l!='Add Friend': if l!='Message': if l!='More Options': if ' mutual friend' not in l: subL.append(l) else: T.append(subL) subL=[] ########################### for t in T[10:]: p={'name':t[0]} for i in range(1,len(t)): k=t[i] #we know the source city by default if 'From ' not in k: if 'Lives in ' in k: p['livesin']=k[9:] elif ' at ' in k: if 'Studied ' in k: h1=k[8:k.find(' at ')] h2=k[k.find(' at ')+4:] if len(h1)>2:p['studwhat']=h1 if " '" in h2: h3=h2[h2.find(" '")+2:] h2=h2[:h2.find(" '")] p['studyear']=h3 p['studwhere']=h2 elif 'Studies ' in k: h1=k[8:k.find(' at ')] h2=k[k.find(' at ')+4:] if len(h1)>2:p['studwhat']=h1 if " '" in h2: h3=h2[h2.find(" '")+2:] h2=h2[:h2.find(" '")] p['studyear']=h3 p['studwhere']=h2 elif 'Works ' in k: h1=k[k.find(' at ')+4:] p['workwhere']=h1 elif 'Worked ' in k: h1=k[k.find(' at ')+4:] p['workwhere']=h1 else: h1=k[:k.find(' at ')] h2=k[k.find(' at ')+4:] p['workwhat']=h1 p['workwhere']=h2 elif ' to ' in k: h1=k[k.find(' to ')+4:] if 'Married ' in k: if ' since ' in h1: h2=h1[h1.find(' since ')+7:] h1=h1[:h1.find(' since ')] p['marriedsince']=h2 p['marriedto']=h1 elif 'Engaged ' in k: if ' since ' in h1: h2=h1[h1.find(' since ')+7:] h1=h1[:h1.find(' since ')] p['marriedsince']=h2 p['marriedto']=h1 elif 'Went ' in k: if " '" in h1: h2=h1[h1.find(" '")+2:] h1=h1[:h1.find(" '")] p['schoolyear']=h2 if len(h1)>2:P[counter]['school']=h1 elif 'Goes' in k: if " '" in h1: h2=h1[h1.find(" '")+2:] h1=h1[:h1.find(" '")] p['schoolyear']=h2 if len(h1)>2:p['school']=h1 elif 'In a relationship with ' in k: h1=k[k.find('In a relationship with ')+23:] if ' since ' in h1: h2=h1[h1.find(' since ')+7:] h1=h1[:h1.find(' since ')] p['marriedsince']=h2 p['marriedto']=h1 else: if k not in p.values(): if 'mutual friend' not in k: if 'Single ' not in k: if 'Read ' not in k: if ' follower' not in k: if 'other' not in p:p['other']=[] p['other'].append(k) p['birth']=varos p['db']=path #append people to global GP.append(p) # In[5]: #flattened array of people NGPhelper={} NGP=[] for k in GP: #keep only unique people across dbs key=str([i for i in k.values() if 'db' not in i]) if key not in NGPhelper: NGPhelper[key]={i:k[i] for i in k if 'db' not in i} NGP=NGPhelper.values() #clean data from "other" duplicates MGP=[] for k in range(len(NGP)): MGP.append({}) for i in NGP[k]: if i!='other': MGP[k][i]=NGP[k][i] for k in range(len(NGP)): for i in NGP[k]: if i=='other': for j in range(len(NGP[k][i])): if NGP[k][i][j] not in MGP[k].values(): MGP[k]['other'+str(j+1)]=NGP[k][i][j] #save data #file('NGP.json','w').write(json.dumps(NGP)) #file('MGP.json','w').write(json.dumps(MGP)) # In[58]: #load existing peoplelist, if exits NGP=json.loads(file("NGP.json").read()) MGP=json.loads(file("MGP.json").read()) # In[59]: first=[] second=[] nms={} nmsa=[] for i in range(len(MGP)): names=MGP[i]['name'].split() MGP[i]['id']=i nms[i]=MGP[i]['name'] try: first.append(names[0]) second.append(names[-1]) except: pass try: nmsa.append(MGP[i]['name']) nmsa.append(MGP[i]['marriedto']) except: pass # In[60]: nmsb={} for i in nmsa: nev=second[int(np.random.uniform()*len(second))]+' '+\ first[int(np.random.uniform()*len(first))] nmsb[i]=nev # In[61]: for i in range(len(MGP)): MGP[i]['name']=nmsb[MGP[i]['name']] if 'marriedto' in MGP[i]: MGP[i]['marriedto']=nmsb[MGP[i]['marriedto']] # In[62]: file('MGPr.json','w').write(json.dumps(MGP)) file('nms.json','w').write(json.dumps(nms)) # In[11]: #record keys, then normalize lsits keys=[] for i in range(len(MGP)): keys.append(MGP[i].keys()) keys=set(np.hstack(keys)) # In[63]: len(MGP) # In[9]: NGP[394] # In[8]: len(NGP) # In[ ]: lists={} for k in keys: lists[k]=set() keys # In[17]: #record lists for i in range(len(MGP)): for j in MGP[i]: lists[j].add(MGP[i][j]) # In[10]: len(MGP) # # Place # In[18]: #load existing placelist, if exits VL=json.loads(file("VL.json").read()) # In[19]: #define locationrenamer def namer(s): if ',' in s: s=s[:s.find(',')] s=s.replace('\xc3\xa8','\xc3\xa9') s=s.replace('\xc3\xa0','\xc3\xa1') s=s.replace('\xc3\xb2','\xc3\xb3') s=s.replace('\xc3\xb9','\xc3\xba') s=s.replace('Mez\xc3\xb6','Mez\xc5\x91') s=s.replace('mez\xc3\xb6','mez\xc5\x91') s=s.replace('Erd\xc3\xb6','Erd\xc5\x91') s=s.replace('fal\xc3\xba','falu') s=s.replace('f\xc3\xbcrd\xc3\xb6','f\xc3\xbcrd\xc3\x91') if s=='Csikszereda': return 'Csíkszereda' elif s=='Miercurea-Ciuc': return 'Csíkszereda' elif s=='Miercurea Ciuc': return 'Csíkszereda' elif s=='Csikr\xc3\xa1kos': return 'Csíkrákos' elif s=='Csikszentimre': return 'Csíkszentimre' elif s=='Chilieni': return 'Kilyénfalva' elif s=='Tusnad Sat': return 'Tusnád' elif s=='Reci': return 'Réty' elif s=='Intorsura Buzaului': return 'Bodzaforduló' elif s=='Ocna De Sus': return 'Felsősófalva' elif s=='Sancraiu De Mures': return 'Marosszentkirály' elif s=='Breaza': return 'Beresztelke' elif s=='Corund': return 'Korond' elif s=='Intorsura Buzaului': return 'Bodzaforduló' elif s=='Intorsura Buzauli': return 'Bodzaforduló' elif s=='Bicfalau': return 'Bikfalva' elif s=='Cernatul-De-Jos': return 'Alsócsernáton' elif s=='Ojdula': return 'Ozsdola' elif s=='Bretcu': return 'Bereck' elif s=='Zabala': return 'Zabola' elif s=='Micfalau': return 'Mikóújfalu' elif s=='Csikszentkir\xc3\xa0ly': return 'Csíkszentkirály' elif s=='Csikszentmikl\xc3\xb3s': return 'Csíkszentmiklós' elif s=='Belgrade': return 'Belgrád' elif s=='S\xc3\xaendominic': return 'Csíkszentdomokos' elif s=='Budapest': return 'Budapest' elif s=='Cluj-Napoca': return 'Kolozsvár' elif s=='Timi\xc8\x99oara': return 'Temesvár' elif s=='Targu-Mures': return 'Marosvásárhely' elif s=='Csik Mindszent': return 'Csíkmindszent' elif s=='Abu Dhabi': return 'Abu Dhabi' elif s=='Tusnad F\xc3\xbcrd\xc3\xb6': return 'Tusnádfürdő' elif s=='Vienna': return 'Bécs' elif s=='Sepsiszentgyorgy': return 'Sepsiszentgyörgy' elif s=='Sf\xc3\xa2ntu-Gheorghe': return 'Sepsiszentgyörgy' elif s=='Paris': return 'Párizs' elif s=='Nagy-V\xc3\xa1rad': return 'Nagyvárad' elif s=='Nitra': return 'Nyitra' elif s=='Krak\xc3\xb3w': return 'Krakkó' elif s=='Tusnad': return 'Tusnád' elif s=='Zetea': return 'Zetelaka' elif s=='Siculeni': return 'Madéfalva' elif s=='Sz\xc3\xa9pviz': return 'Csíkszépvíz' elif s=='Sibiu': return 'Nagyszeben' elif s=='Bucharest': return 'Bukarest' elif s=='Oradea': return 'Nagyvárad' elif s=='Hodmezovasarhely': return 'Hódmezővásárhely' elif s=='Brussels': return 'Brüsszel' elif s=='Cologne': return 'Köln' elif s=='Dealu': return 'Oroszhegy' elif s=='Delne': return 'Csíkdelne' elif s=='Sz\xc3\xa9kelykeresztur': return 'Székelykeresztúr' elif s=='Bulgareni': return 'Bogárfalva' elif s=='Sighetu Marmatiei': return 'Máramarossziget' elif s=='Odorheiu Secuiesc': return 'Székelyudvarhely' elif s=='Athens': return 'Athén' elif s=='Brasov': return 'Brassó' elif s=='Beta': return 'Béta' elif s=='Martinis': return 'Homoródszentmárton' elif s=='Copenhagen': return 'Koppenhága' elif s=='Buda': return 'Budapest' elif s=='Neumarkt Am Mieresch': return 'Marosvásárhely' elif s=='Vlahita': return 'Szentegyháza' elif s=='Szentegyházasfalu': return 'Szentegyháza' elif s=='Fenyokut': return 'Fenyőkút' elif s=='Felsoboldogfalva': return 'Felsőboldogfalva' elif s=='Baile Tusnad': return 'Tusnádfürdő' elif s=='Szegedin': return 'Szeged' elif s=='Küküllokeményfalva': return 'Küküllőkeményfalva' elif s=='Oraseni': return 'Városfalva' elif s=='Nyikomalomfalva': return 'Nyikómalomfalva' elif s=='Szatmár-Németi': return 'Szatmárnémeti' elif s=='Lövete': return 'Lövéte' elif s=='Kézdi Almas': return 'Kézdialmás' elif s=='Cristuru Secuiesc': return 'Székelykeresztúr' elif s=='Sacueni': return 'Székelyhíd' elif s=='Szekelyszentmihaly': return 'Székelyszentmihály' elif s=='Debreczen': return 'Debrecen' elif s=='Liban': return 'Libán' elif s=='Leipzig': return 'Lipcse' elif s=='Pasareni': return 'Backamadaras' elif s=='Munich': return 'München' elif s=='Nuremberg': return 'Nüremberg' elif s=='Amsterdam': return 'Amszterdam' elif s=='Csik-Kozmas': return 'Csíkkozmás' elif s=='Csiktaploca': return 'Csíktaploca' elif s=='Csikszentsimon': return 'Csíkszentsimon' elif s=='Csikszentmárton': return 'Csíkszentmárton' elif s=='Vacaresti': return 'Vacsárcsi' elif s=='Milan': return 'Milánó' elif s=='Csikszentgyörgy': return 'Csíkszentgyörgy' elif s=='Nadejdea': return 'Ajnád' elif s=='Csikszenttamás': return 'Csíkszenttamás' elif s=='Gyor': return 'Győr' elif s=='London Borough of Camden': return 'London' elif s=='Csikszentdomokos': return 'Csíkszentdomokos' elif s=='Csikszentkirály': return 'Csíkszentkirály' elif s=='Madaras': return 'Csíkmadaras' elif s=='Karcfalva': return 'Csíkkarcfalva' elif s=='Ciceu': return 'Csíkcsicsó' elif s=='Izvoare': return 'Ivó' elif s=='Gyomro': return 'Gyömrő' elif s=='Sf\xc3\xaentu Gheorghe': return 'Sepsiszentgyörgy' elif s=='Baraolt': return 'Barót' elif s=='K\xc3\xb8benhavn': return 'Koppenhága' elif s=='Mik\xc3\xb4ujfal\xc3\xba': return 'Mikóújfalu' elif s=='Zagon': return 'Zágon' elif s=='Sarmasul': return 'Salamás' elif s=='Zalau': return 'Zilah' elif s=='Simleu Silvaniei': return 'Sepsiszentgyörgy' elif s=='Zalan': return 'Zalán' elif s=='Oradea-Mare': return 'Nagyvárad' elif s=='Ormenis': return 'Ürmös' elif s=='Bicsad': return 'Sepsibükszád' elif s=='Ozun': return 'Uzon' elif s=='Arkos': return 'Árkos' elif s=='Gheorgheni': return 'Gyergyószentmiklós' elif s=='S\xc3\xa2npetrul': return 'Barcaszentpéter' elif s=='Geneva': return 'Genf' elif s=='Breda': return 'Bréda' elif s=='Zoltan': return 'Zoltán' elif s=='Leliceni': return 'Csíkszentlélek' elif s=='Suatu': return 'Magyarszovát' elif s=='Pest': return 'Budapest' elif s=='Bacau': return 'Bákó' elif s=='Varfalau': return 'Várfalva' elif s=='Biksz\xc3\xa1d': return 'Sepsibükszád' elif s=='Satu Mare': return 'Szatmárnémeti' elif s=='Köröspatak': return 'Kőröspatak' elif s=='Prague': return 'Prága' elif s=='Turin': return 'Torinó' elif s=='Poiana Largului': return 'Hosszúmező' elif s=='Beius': return 'Belényes' elif s=='Csics\xc3\xb3': return 'Csíkcsicsó' elif s=='Rome': return 'Róma' elif s=='Sovata Bai': return 'Szováta' elif s=='veroce': return 'Verőce' elif s=='Nagy-Sz\xc3\xa9ben': return 'Nagyszeben' elif s=='Iasi': return 'Jászvásár' elif s=='Rupea': return 'Kőhalom' elif s=='Ludu\xc8\x99': return 'Marosludas' elif s=='Paingeni': return 'Póka' elif s=='Havadto': return 'Havadtő' elif s=='Reghinul': return 'Szászrégen' elif s=='S\xc3\xa2ncraiul-De-Mures': return 'Marosszentkirály' elif s=='Valureni': return 'Székelykakasd' elif s=='Ditro': return 'Gyergyóditró' elif s=='Sz\xc3\xa1rhegy': return 'Gyergyószárhegy' elif s=='Florence': return 'Firenze' elif s=='Bogata': return 'Marosbogát' elif s=='Alunis': return 'Magyaró' elif s=='Selanik (thessaloniki) Greece': return 'Thessaloniki' elif s=='Lunca Bradului': return 'Palotailva' elif s=='Ceuasul-De Campie': return 'Mezőcsávás' elif s=='Sangeorgiul De Mures': return 'Marosszentgyörgy' elif s=='Sighisoara': return 'Segesvár' elif s=='Gyergyo': return 'Gyergyószentmiklós' elif s=='Ogra': return 'Marosugra' elif s=='Ujtusn\xc3\xa1d': return 'Újtusnád' elif s=='Miercurea Nirajului': return 'Nyárádszereda' elif s=='Floresti': return 'Szászfenes' elif s=='Santioana-De-Mures': return 'Csittszentiván' elif s=='Maroskeresztur': return 'Maroskeresztúr' elif s=='Sangeorgiu-De-Padure': return 'Erdőszentgyörgy' elif s=='Cristesti': return 'Maroskeresztúr' elif s=='Sangeorg-De Mures': return 'Marosszentgyörgy' elif s=='Dej': return 'Dés' elif s=='Csikfalva': return 'Csíkfalva' elif s=='Marghita': return 'Margitta' elif s=='Valea Izvoarelor': return 'Buzásbesenyő' elif s=='Corunca': return 'Koronka' elif s=='Sovata': return 'Szováta' elif s=='Ny\xc3\xa1radremete': return 'Nyárádremete' elif s=='Cehu Silvaniei': return 'Szilágycseh' elif s=='B\xc3\xa1lav\xc3\xa1s\xc3\xa1r,': return 'Balavásár' elif s=='Csomafalva': return 'Gyergyócsomafalva' elif s=='Szigetsentmiklos': return 'Szigetszentmiklós' elif s=='Mik\xc3\xb4ujfal\xc3\xb9': return 'Mikóújfalu' elif s=='Bibarczflava': return 'Bibarcfalva' elif s=='Bradut': return 'Fenyéd' elif s=='Huedin': return 'Bánffyhunyad' elif s=='New Delhi': return 'Újdelhi' elif s=='Galanta': return 'Galánta' elif s=='Beirut': return 'Bejrút' elif s=='Riyadh': return 'Rijád' elif s=='Jerusalem': return 'Jeruzsálem' elif s=='Godollo': return 'Gödöllő' elif s=='Balatonfuzfo': return 'Balatonfűzfő' elif s=='Fels\xc3\xb6sofalva': return 'Felsősófalva' elif s=='Bodok': return 'Sepsibodok' elif s=='Bodoc': return 'Sepsibodok' elif s=='Biborteni': return 'Bibarcfalva' elif s=='Tarnaveni': return 'Dicsőszentmárton' elif s=='Bremen': return 'Bréma' elif s=='Targu-Sacuesc': return 'Kézdivásárhely' elif s=='Ungheni': return 'Nyárádtő' elif s=='Racosu De Jos': return 'Alsórákos' elif s=='Mikl\xc3\xb3svar': return 'Miklósvár' elif s=='V\xc4\x81sad': return 'Vasad' elif s=='Sf\xc3\xa2ntul-Gheorghe': return 'Sepsiszentgyörgy' elif s=='Malnas Bai': return 'Málnásfürdő' elif s=='Colonia Bod': return 'Botfalusi Cukorgyártelep' elif s=='Ujfal\xc3\xba': return 'Újfalu' elif s=='Doboseni': return 'Székelyszáldobos' elif s=='Batanii Mari': return 'Nagybacon' elif s=='Rakos': return 'Felsőrákos' elif s=='Gonyu': return 'Gönyű' elif s=='Capeni': return 'Köpec' elif s=='K\xc3\xb6pecz': return 'Köpec' elif s=='Senec': return 'Szenc' elif s=='Petrosani': return 'Petrozsény' elif s=='Biharia': return 'Bihar' elif s=='Racos': return 'Felsőrákos' elif s=='Erdofule': return 'Erdőfüle' elif s=='Kopec': return 'Köpec' elif s=='Sarmasag': return 'Sarmaság' elif s=='Aiud': return 'Nagyenyed' elif s=='Fels\xc3\xb6r\xc3\xa1kos': return 'Felsőrákos' elif s=='Ullo': return 'Üllő' elif s=='Alba Iulia': return 'Gyulafehérvár' elif s=='Felso Szeli': return 'Csíkszereda' elif s=='Kom\xc3\xa1ndo': return 'Kommandó' elif s=='Remetea': return 'Gyergyóremete' elif s=='S\xc3\xa2nnicolaul-De-Munte': return 'Hegyközszentmiklós' elif s=='Tulghes': return 'Gyergyótölgyes' elif s=='Marosfo': return 'Marosfő' elif s=='Lazarea': return 'Gyergyószárhegy' elif s=='Gyimesfels\xc3\xb6lok': return 'Gyimesfelsőlok' elif s=='K\xc3\xa1szonaltiz': return 'Kászonaltíz' elif s=='Suseni': return 'gyergyóújfalu' elif s=='Gyerg\xc3\xb2szentmikl\xc3\xb2s': return 'Gyergyószentmiklós' elif s=='Magyaro': return 'Magyaró' elif s=='Deva': return 'Déva' elif s=='Szatm\xc3\xa1r': return 'Szatmárnémeti' elif s=='Lacu Rosu': return 'Gyilkostó' elif s=='K\xc3\xb6r\xc3\xb6sszegap\xc3\xa1ti': return 'Kőrősszegapáti' elif s=='Ditrau': return 'Gyergyóditró' elif s=='Naples': return 'Nápoly' elif s=='T\xc3\xaergu Secuiesc': return 'Kézdivásárhely' elif s=='Turia': return 'Torja' elif s=='K\xc3\xa0szonuifal\xc3\xb9': return 'Kászonújfalu' elif s=='Cernat': return 'Csernáton' elif s=='Cosnea': return 'Kóstelek' elif s=='Mereni': return 'Kézdialmás' elif s=='Bretcul': return 'Bereck' elif s=='Poian': return 'Kézdiszentkereszt' elif s=='Cernatul-De-Sus': return 'Csernáton' elif s=='Icafalau': return 'Ikafalva' elif s=='Bereczk': return 'Bereck' elif s=='Zau De C\xc3\xaempie': return 'Mezőzáh' elif s=='Hatuica': return 'Hatolyka' elif s=='Sarfalva': return 'Sárfalva' elif s=='K\xc3\xa9zdi-Mart\xc3\xb2nos': return 'Kézdimartonos' elif s=='Csiksomly\xc3\xb3': return 'Csíksomlyó' elif s=='Beijing': return 'Peking' elif s=='Vlaha': return 'Magyarfenes' elif s=='Baciu': return 'Kisbács' elif s=='Reghin': return 'Szászrégen' elif s=='Eted': return 'Etéd' elif s=='Carei': return 'Nagykároly' elif s=='Felsolajos': return 'Felsőlajos' elif s=='Paltinis': return 'Kecsed' elif s=='Atid': return 'Etéd' elif s=='Lopadea Noua': return 'Magyarlapád' elif s=='Andreeni': return 'Székelyandrásfalva' elif s=='Diosig': return 'Bihardiószeg' elif s=='Emod': return 'Emőd' elif s=='Cristur': return 'Székelykeresztúr' elif s=='Andr\xc3\xa1sfalva': return 'Székelyandrásfalva' elif s=='Pilisborosjeno': return 'Pilisborosjenő' elif s=='Kiskoros': return 'Kiskőrös' elif s=='Als\xc3\xb2b\xc3\xb2ldogfalva': return 'Alsóboldogfalva' elif s=='Vetca': return 'Székelyvécke' elif s=='Goagiu': return 'Gagy' elif s=='Betesti': return 'Betfalva' elif s=='Kaposfo': return 'Kaposfő' elif s=='Bodogaia': return 'Alsóboldogfalva' elif s=='Siklodi Oldal': return 'Siklód' elif s=='Koszegszerdahely': return 'Kőszegszerdahely' elif s=='Ilieni': return 'Lukailencfalva' elif s=='Lunca De Jos': return 'Gyimesközéplok' elif s=='Tapioszecso': return 'Tápiószecső' elif s=='Ujsz\xc3\xa8kely': return 'Újszékely' elif s=='Turda': return 'Torda' elif s=='Jiboul': return 'Zsibó' elif s=='Agnita': return 'Szentágota' elif s=='Cisnadie': return 'Nagydisznód' elif s=='Peregu Mare': return 'Németpereg' elif s=='Constanta': return 'Konstanca' elif s=='Hezeris': return 'Lugosegres' elif s=='Tekeropatak': return 'Gyergyótekerőpatak' elif s=='Galati': return 'Galac' elif s=='Covasna': return 'Kovászna' elif s=='Kronstadt': return 'Brassó' elif s=='T\xc3\xa2rgu Jiu': return 'Zsilvásárhely' elif s=='S\xc3\xa2ndominic': return 'Csíkszentdomokos' elif s=='Chisineu Chis': return 'Kőrőskisjenő' elif s=='Bistrita': return 'Beszterce' elif s=='Izvorul Muresului': return 'Marosfő' elif s=='Gilau': return 'Gyalu' elif s=='Corois\xc3\xa2nmartin': return 'Kóródszentmárton' elif s=='Marculeni': return 'Márkod' elif s=='Sarmas': return 'Salamás' elif s=='Palanca': return 'Palánka' elif s=='Odorheiul Secuiesc': return 'Székelyudvarhely' elif s=='Talmacel': return 'Kistalmács' elif s=='Adjud': return 'Egyedhalma' elif s=='Baia Mare': return 'Nagybánya' elif s=='Valea Mica': return 'Pokolpatak' elif s=='Ghimes-Faget': return 'Gyimesbükk' elif s=='Ruganesti': return 'Rugonfalva' elif s=='Toplita-Ciuc': return 'Maroshévíz' elif s=='Belin': return 'Bölön' elif s=='Gurghiu': return 'Görgényszentimre' elif s=='Jenofalva': return 'Csíkjenőfalva' elif s=='Comanesti': return 'Kománfalva' elif s=='Balan': return 'Balánbánya' elif s=='Miercurea Ciuc': return 'Csíkszereda' elif s=='T\xc3\xa2rgu Jiu': return 'Zsilvásárhely' elif s=='Cristolt': return 'Nagykeresztes' elif s=='Toplita': return 'Maroshévíz' elif s=='Miercurea-Ciucului': return 'Csíkszereda' elif s=='Chiheru De Sus': return 'Felsőköhér' elif s=='Borsec': return 'Borszék' elif s=='Vasluiul': return 'Vaslui' elif s=='Bucuresti-Noi': return 'Bukarest' elif s=='Istanbul': return 'Isztambul' elif s=='Targu-Neamt': return 'Németvásár' elif s=='Uzinele Vlahita': return 'Szentegyháza' elif s=='Szasz R\xc3\xa9gen': return 'Szászrégen' elif s=='Baile Homorod': return 'Homoródfürdő' elif s=='Corfu': return 'Korfu' elif s=='Lueta': return 'Lövéte' elif s=='Praid': return 'Parajd' elif s=='Mindszent': return 'Csíkmindszent' elif s=='Homorodfurdo': return 'Homoródfürdő' elif s=='Homorod-Bai': return 'Homoródfürdő' elif s=='Chibed': return 'Kibéd' elif s=='Uzonkaf\xc3\xbcrd\xc3\xb6': return 'Uzonkafürdő' elif s=='Borzsova': return 'Csíkborzsova' elif s=='Mina Sarmmasag': return 'Sarmaság' elif s=='Iernut': return 'Radnót' elif s=='Medias': return 'Szászmedgyes' elif s=='Bratislava': return 'Pozsony' elif s=='C\xc3\xa2mpia Turzi': return 'Aranyosgyéres' elif s=='C\xc3\xa2mpia Turzi': return 'Aranyosgyéres' elif s=='Mosuni': return 'Székelymoson' elif s=='Hunedoara': return 'Vajdahunyad' elif s=='Damieni': return 'Deményháza' elif s=='Chilieni': return 'Kilyén' elif s=='Nadlac': return 'Nagylak' elif s=='Sacadat': return 'Szakadát' elif s=='Baile Sovata': return 'Szováta' elif s=='Csengod': return 'Csengőd' elif s=='Copaceni': return 'Koppánd' elif s=='Livezeni': return 'Jedd' elif s=='Viisoara': return 'Csatófalva' elif s=='Voivodeni': return 'Vajdaháza' elif s=='Rastolita': return 'Ratosnya' elif s=='Serbeni': return 'Soropháza' elif s=='S\xc3\xa2npetru-De-C\xc3\xa2mpie': return 'Mezőszentpéter' elif s=='Iernuteni': return 'Randótfája' elif s=='Hermannstadt': return 'Nagyszeben' elif s=='Nadasa': return 'Görgénynádas' elif s=='City of Brussels': return 'Brüsszel' elif s=='Trei Sate': return 'Hármasfalu' elif s=='Mar\xc3\xb3s Vecs': return 'Marosvécs' elif s=='Gurghiul': return 'Görgényszentimre' elif s=='Petelea': return 'Petele' elif s=='Jabenita': return 'Görgénysóakna' elif s=='Valenii De Mures': return 'Disznajó' elif s=='Orfu': return 'Orfű' elif s=='Fitcau': return 'Fickópataka' elif s=='Dezmir': return 'Dezmér' elif s=='Podu Turcului': return 'Törökpadja' elif s=='Goreni': return 'Dedrádszéplak' elif s=='Mitresti': return 'Nyárádszentmárton' elif s=='Ibanesti': return 'Libánfalva' elif s=='Gherla': return 'Szamosújvár' elif s=='Solovastrul': return 'Görgényoroszfalu' elif s=='Reghinul Sashsisch': return 'Szászrégen' elif s=='Brancovenesti': return 'Marosvécs' elif s=='Zadareni': return 'Zádorlac' elif s=='Reghin-Sat': return 'Szászrégen' elif s=='Beica De Jos': return 'Alsóbölkény' elif s=='Baita': return 'Laposbánya' elif s=='Sacalu De Padure': return 'Magyarerdőszakál' elif s=='Ideciu De Sus': return 'Alsóidecs' elif s=='Chiheru de Jos': return 'Alsóköhér' elif s=='Beica De Sus': return 'Felsőbölkény' elif s=='Ideciul-De-Jos': return 'Alsóidecs' elif s==' Tapioszecso': return 'Tápiószecső' elif s=='Glajarie': return 'Görgényüvegcsűr' elif s=='Blaj': return 'Balázsfalva' elif s=='G\xc3\xb6rg\xc3\xa9ny\xc3\xbcvegcs\xc3\xbcr': return 'Görgényüvegcsűr' elif s=='Martinesti': return 'Pusztaszentmárton' elif s=='Luna De Sus': return 'Szászlóna' elif s=='Chesau': return 'Mezőkeszü' elif s=='baile Felix': return 'Félixfürdő' elif s=='Dubai': return 'Dubaj' elif s=='Nimigea De Jos': return 'Magyarnemegye' elif s=='C\xc3\xa2mpia Turzii': return 'Aranyosgyéres' elif s=='Craciunelul-De-Jos': return 'Alsókarácsonfalva' elif s=='Valenii': return 'Disznajó' elif s=='Laslea': return 'Szászszentlászló' elif s=='Petrilaca': return 'Oláhpéterlaka' elif s=='Nazna': return 'Náznánfalva' elif s=='Dragomiresti': return 'Dragomérfalva' elif s=='Balauseri': return 'Balavásár' elif s=='Saschiz': return 'Szászkézd' elif s=='S\xc3\xa2ntioana': return 'Marosszentanna' elif s=='Mica': return 'Mikefalva' elif s=='Seleusu-Mare': return 'Nagyszőlős' elif s=='Odrihei': return 'Vámosudvarhely' elif s=='Danes': return 'Dános' elif s=='Suplac': return 'Széplak' elif s=='Resita': return 'Resicabánya' elif s=='Codlea': return 'Feketehalom' elif s=='Tigmandru': return 'Cikmántor' elif s=='Remetea Lunca': return 'Hosszúremete' elif s=='Soardu': return 'Küküllősárd' elif s=='Szentharomsag': return 'Szentháromság' elif s=='Corbu': return 'Gyergyóholló' elif s=='St\xc3\xaenceni': return 'Gödemesterháza' elif s=='St\xc3\xa2nceni': return 'Gödemesterháza' elif s=='Vertesszolos': return 'Vértesszőlős' elif s=='Gheorghieni': return 'Gyergyószentmiklós' elif s=='Deda': return 'Déda' elif s=='Deda Bistra': return 'Dédabisztra' elif s=='Bistra Muresului': return 'Dédabisztra' elif s=='Lugoj': return 'Lugos' elif s=='Sausa': return 'Székelysóspatak' elif s=='Hodosa-De-Ciuc': return 'Csíkhodos' elif s=='Subcetate': return 'Zeteváralja' elif s=='Pantelimon': return 'Bukarest' elif s=='Capilnita': return 'Kápolnásfalu' elif s=='Santana-De-Mures': return 'Marosszentanna' elif s=='Bocsa': return 'Boksánbánya' elif s=='S\xc3\xa2nnicolau Mare': return 'Nagyszentmiklós' elif s=='S\xc3\xa2nnicolaul Mare': return 'Nagyszentmiklós' elif s=='S\xc3\xa2npetru Mic': return 'Kisszentpéter' elif s=='S\xc3\xaennicolaul Mare': return 'Nagyszentmiklós' elif s=='St\xc3\xa2nceni': return 'Gödemesterháza' elif s=='Ciobotani': return 'Csobotány' elif s=='Lunca De Sus': return 'Gyimesfelsőlok' elif s=='Ghindari': return 'Makkfalva' elif s=='Caporal Alexa': return 'Erdőskerek' elif s=='Coldau': return 'Várkudu' elif s=='Bicaz Chei': return 'Békás' elif s=='Bilbor': return 'Bélbor' elif s=='Moscow': return 'Moszkva' else: return s # In[20]: def code(i): i=i.replace('Sonderjylland','') i=i.replace('\xc3\xa8','\xc3\xa9') i=i.replace('\xc3\xa0','\xc3\xa1') i=i.replace('\xc3\xb2','\xc3\xb3') i=i.replace('\xc3\xb9','\xc3\xba') i=i.replace('Mez\xc3\xb6','Mez\xc5\x91') i=i.replace('mez\xc3\xb6','mez\xc5\x91') i=i.replace('Erd\xc3\xb6','Erd\xc5\x91') i=i.replace('fal\xc3\xba','falu') i=i.replace('f\xc3\xbcrd\xc3\xb6','f\xc3\xbcrd\xc3\x91') if i=='Szentegyházasfalu': tocode='Valhita, Harghita, Romania' elif i=='Szentegyh\xc3\xa1zasfalu': tocode='Valhita, Harghita, Romania' elif i=='Sarmasul, Mures, Romania': tocode='Sarmas, Mures, Romania' elif i=='Ilencfalva, Mures, Romania': tocode='Ilieni, Mures, Romania' elif i=='Reghinul, Mures, Romania': tocode='Reghin, Mures, Romania' elif i=='S\xc3\xa2ncraiul-De-Mures, Mures, Romania': tocode='Sancraiu de Mures, Mures, Romania' elif i=='Monoritoko, Mahajanga, Madagascar': tocode='Manaritoka, Mahajanga, Madagascar' elif i=='Sangeorg-De Mures, Mures, Romania': tocode='Sangeorgiu De Mures, Mures, Romania' elif i=='S\xc3\xb6lden, Austria': tocode='Solden, Austria' elif i=='Pjelax, L\xc3\xa4nsi-Suomen L\xc3\xa4\xc3\xa4ni, Finland': tocode='Pjelax, Finland' elif i=='Siklodi Oldal, Mures, Romania': tocode='Siklod, Mures, Romania' elif i=='Kereszt\xc3\xbar, Timis, Romania': tocode='Cherestur, Timis, Romania' elif i=='Jiboul, Salaj, Romania': tocode='Jibou, Salaj, Romania' elif i=='Szasz R\xc3\xa9gen, Mures, Romania': tocode='Reghin, Mures, Romania' elif i=='Fick\xc3\xb3, Mures, Romania': tocode='Fitcau, Mures, Romania' elif i=='Gurghiul, Mures, Romania': tocode='Gurghiu, Mures, Romania' elif i=='Mar\xc3\xb3s Vecs, Mures, Romania': tocode='Brancovenesti, Mures, Romania' elif i=='Felfalu, Mures, Romania': tocode='Suseni, Mures, Romania' elif i=='Solovastrul, Mures, Romania': tocode='Solovastru, Mures, Romania' elif i=='Reghinul Sashsisch, Mures, Romania': tocode='Reghin, Mures, Romania' elif i=='Ideciul-De-Jos, Mures, Romania': tocode='Ideciu De Jos, Mures, Romania' elif i=='Craciunelul-De-Jos, Alba, Romania': tocode='Craciunelu De Jos, Alba, Romania' elif i=='Seleusu-Mare, Mures, Romania': tocode='Seleus, Mures, Romania' elif i=='Chendu Mare, Mures, Romania': tocode='Chend, Mures, Romania' elif i=='Chendu Mare, Mures, Romania': tocode='Chend, Mures, Romania' elif i=='Galautasi, Mures, Romania': tocode='Galautasi, Romania' elif i=='Iermata Neagra, Timis, Romania': tocode='Iermata Neagra, Romania' elif i=='Kiskend, Mures, Romania': tocode='Chendu, Mures, Romania' elif i=='Teremeujfal\xc3\xb9, Mures, Romania': tocode='Satu Nou, Mures, Romania' elif i=='Eremitul, Mures, Romania': tocode='Eremitu, Mures, Romania' elif i=='Szentbenedek, Mures, Romania': tocode='Manastirea, Cluj, Romania' elif i=='Baczkamadaras, Mures, Romania': tocode='Pasareni, Mures, Romania' elif i=='Arpasel, Timis, Romania': tocode='Arpasel, Bihor, Romania' elif i=='Grintiesu Mic, Neamt, Romania': tocode='Grinties, Neamt, Romania' elif i=='Batos': tocode='Batos, Mures, Romania' elif i=='Toplita-Ciuc, Harghita, Romania': tocode='Toplita, Harghita, Romania' elif i=='Kopec': tocode='Capeni, Harghita, Romania' elif i=='S\\xc3\\xa2nger': tocode='Sanger, Mures, Romania' elif i=='Iv\xc3\xb3pataka, Harghita, Romania': tocode='Izvoare, Harghita, Romania' elif i=='Iv\xc3\xb2pataka, Harghita, Romania': tocode='Izvoare, Harghita, Romania' elif i=='Nagymedes\xc3\xa9r, Harghita, Romania': tocode='Simonesti, Harghita, Romania' elif i=='Nagymedes\xc3\xa8r, Harghita, Romania': tocode='Simonesti, Harghita, Romania' elif i=='Beseny\xc3\xb6, Covasna, Romania': tocode='Moacsa, Covasna, Romania' elif i=='Csikszentm\xc3\xa0rton, Covasna, Romania': tocode='Sinmartin, Harghita, Romania' elif i=='Csikszentm\xc3\xa1rton, Covasna, Romania': tocode='Sinmartin, Harghita, Romania' elif i=='Kad\xc3\xa0cs, Harghita, Romania': tocode='Atia, Harghita, Romania' elif i=='Kad\xc3\xa1cs, Harghita, Romania': tocode='Atia, Harghita, Romania' elif i=='Erlenbach \xc3\x9cber Wittlich, Rheinland-Pfalz, Germany': tocode='Erlenbach bei Kandel' elif i=='K\xc3\xb6v\xc3\xa1r, Covasna, Romania': tocode='Sanzieni, Covasna' elif i=='Biksz\xc3\xa1d, Covasna, Romania': tocode='Bixad, Covasna' elif i=='M\xc3\xa1rtonfalva, Covasna, Romania': tocode='Catalina, Covasna' elif i=='In\xc3\xa1rcs, Heves, Hungary': tocode='In\xc3\xa1rcs, Hungary' elif i=='Fels\xc3\xb6csern\xc3\xa1ton, Covasna, Romania': tocode='Cernat, Covasna' elif i=='K\xc3\xa1szonuifalu, Covasna, Romania': tocode='Casinu Nou, Romania' elif i=='Csics\xc3\xb3, Harghita, Romania': tocode='Ciceu, Romania' elif i=='Kom\xc3\xa1ndo, Covasna, Romania': tocode='Comandau, Covasna' elif i=='M\xc3\xa9nas\xc3\xa1g, Harghita, Romania': tocode='Armaseni, Harghita, Romania' elif i=='Csat\xc3\xb3szeg, Covasna, Romania': tocode='Cetatuia, Romania' elif i=='Hargitaf\xc3\xbcrd\xc3\x91, Harghita, Romania': tocode='Harghita Bai, Romania' elif i=='Ujfalu, Harghita, Romania': tocode='Armaseni, Romania' elif i=='K\xc3\xa1szonfeltiz, Covasna, Romania': tocode='Plaiesii de Jos, Romania' elif i=='P\xc3\xa1lfalva, Harghita, Romania': tocode='Pauleni, Harghita, Romania' elif i=='\xef\xbf\xbdSz\xc3\xa1r, Komarom-Esztergom, Hungary': tocode='Szarliget, Hungary' elif i=='Fels\xc3\xb6r\xc3\xa1kos, Harghita, Romania': tocode='Racu, Harghita, Romania' elif i=='F\xc3\xbcle, Harghita, Romania': tocode='Filia, Romania' elif i=='Sz\xc3\xa9kelyders, Harghita, Romania': tocode='Darjiu, Romania' elif i=='Andr\xc3\xa1sfalva, Harghita, Romania': tocode='Santana, Mures, Romania' elif i=='Uzonkaf\xc3\xbcrd\xc3\x91, Covasna, Romania': tocode='Ozunca-Bai, Romania' elif i=='L\xc3\xa1z\xc3\xa1rfalva, Covasna, Romania': tocode='Lazaresti, Romania' elif i=='Sz\xc3\xa1razpatak, Covasna, Romania': tocode='Aita Seaca, Romania' elif i=='K\xc3\xa1szoninper, Covasna, Romania': tocode='Imper, Romania' elif i=='Marosh\xc3\xa9viz, Mures, Romania': tocode='Toplita, Romania' elif i=='Sn\xc3\xa6bum, Nordjylland, Denmark': tocode='Denmark' elif i=='Szentkir\xc3\xa1ly, Covasna, Romania': tocode='Sincraiu, Covasna, Romania' elif i=='Sikassz\xc3\xb3, Harghita, Romania': tocode='Sicasau, Romania' elif i=='Tam\xc3\xa1sfalva, Covasna, Romania': tocode='Tamaseni, Romania' elif i=='K\xc3\xa1szonaltiz, Covasna, Romania': tocode='Plaiesii de Jos, Romania' elif i=='Sz\xc3\xa9keylveczke, Mures, Romania': tocode='Vetca, Romania' elif i=='K\xc3\xb6pecz, Covasna, Romania': tocode='Capeni, Romania' elif i=='Komoll\xc3\xb3, Covasna, Romania': tocode='Reci, Romania' elif i=='Bard\xc3\xb3cz, Harghita, Romania': tocode='Bradut, Romania' elif i=='Inferno, Cuanza Sul, Angola': tocode='Sumbe, Cuanza Sul, Angola' elif i=='K\xc4\xb1na, Bolu, Turkey': tocode='Bolu' elif i=='Als\xc3\xb3csern\xc3\xa1ton, Covasna, Romania': tocode='Cernat, Romania' else: tocode=i return tocode # In[21]: notVL=set() for i in lists['livesin']: if i not in VL: notVL.add(i) # In[22]: len(notVL) # In[54]: for i in notVL: try: w=Geocoder.geocode(code(i)) VL[i]={"coord":w.coordinates,"raw":w.raw,"country":w.country} except: print i,'|',code(i) break # In[59]: file('VL.json','w').write(json.dumps(VL)) # ## Names # In[60]: PL={} for i in VL.keys(): if type(i) is unicode: PL[i]=namer(i.encode('utf8')) else: PL[i]=namer(i) # In[61]: file('PL.json','w').write(json.dumps(PL)) # # School # In[62]: def school(i): if i=='BME': tocode='Budapesti Muszaki Egyetem' elif i=='Life :*': tocode='Marton Arong Gimnazium' elif i=='\xe0\xb9\x82\xe0\xb8\xa3\xe0\xb8\x87\xe0\xb9\x80\xe0\xb8\xa3\xe0\xb8\xb5\xe0\xb8\xa2\xe0\xb8\x99\xe0\xb8\x9a\xe0\xb9\x89\xe0\xb8\xb2\xe0\xb8\x99\xe0\xb8\xab\xe0\xb8\x99\xe0\xb8\xad\xe0\xb8\x87\xe0\xb9\x83\xe0\xb8\xab\xe0\xb8\x8d\xe0\xb9\x88': tocode='Marton Arong Gimnazium' else: tocode=i return tocode+' school' # In[63]: SL={} # In[64]: from googleplaces import GooglePlaces, types, lang #YOUR_API_KEY = 'AIzaSyDzdVjSa6UoJHZvYgArra3Dt3WSZeUH4nQ' #YOUR_API_KEY = 'AIzaSyAerhuhvdfA8U16y8_uxnTO2qrO-ddaogY' #YOUR_API_KEY = 'AIzaSyCJIsIQnCMi-DgF6AT0ZdeWnp8p9JUBG2U' YOUR_API_KEY = 'AIzaSyDSEWM8wPAIPyz7lKxQ4MlNpchSORik05A' google_places = GooglePlaces(YOUR_API_KEY) # In[67]: for i in lists['school']: if i not in SL: try: query_result = google_places.text_search(i.decode('utf8')) for place in query_result.places: SL[i]={"name":place.name,"loc":place.geo_location,"id":place.place_id} except: print i,'|',school(i) break # In[88]: SL2={} for i in SL: SL2[i]=SL[i] SL2[i]['loc']={'lat':float(SL[i]['loc']['lat']),'lng':float(SL[i]['loc']['lng'])} file('SL.json','w').write(json.dumps(SL2)) # # Stud # In[89]: def uni(i): if i=='............................': tocode='No' elif i=='Erdoszentgyorgy': tocode='No' elif i=='Sehol': tocode='No' elif i=='Lesz': tocode='No' elif i=='oooo': tocode='No' elif i=='.......................': tocode='No' elif i=='majd k\xc3\xa9s\xc5\x91bb': tocode='No' elif i=='Ideciu de Jos': tocode='No' elif i=='.............................': tocode='No' elif i=='szakliceum': tocode='No' elif i=='Romania': tocode='No' elif i=='Liceu': tocode='No' elif i=='nincs \xc3\xa9s nem is lesz XD': tocode='No' elif i=='nici gand': tocode='No' elif i=='aaaa': tocode='No' elif i=='SEMI': tocode='No' elif i=='ugyanott': tocode='No' else: tocode=i return tocode+' university' # In[90]: #studlist UL={} #not resolved list noUL=set() # In[2]: from googleplaces import GooglePlaces, types, lang #YOUR_API_KEY = 'AIzaSyDzdVjSa6UoJHZvYgArra3Dt3WSZeUH4nQ' #YOUR_API_KEY = 'AIzaSyCJIsIQnCMi-DgF6AT0ZdeWnp8p9JUBG2U' #YOUR_API_KEY = 'AIzaSyDSEWM8wPAIPyz7lKxQ4MlNpchSORik05A' #YOUR_API_KEY = 'AIzaSyCXIzhTpOq8kmx5bu2SuFWAZBE6vgyJgO0' #YOUR_API_KEY = 'AIzaSyCGofhVYKtYMbU4j2lePW6jrfkBo7y9AAw' #YOUR_API_KEY = 'AIzaSyB4sTQjtprWu7hP_LDHw0Hicg3tCqBbgRg' #YOUR_API_KEY = 'AIzaSyBR1wdTdTpod7baeVHLxEUtSuYcGVBG3S0' #YOUR_API_KEY = 'AIzaSyBd-9a-Dnl7x7BjWXQXdf0z2klN2Xo14AA' #YOUR_API_KEY = 'AIzaSyBkLuQMPqFZex592hJoERW5lm--ymi99nw' #YOUR_API_KEY = 'AIzaSyBUrDo2NogTLF07-hbIRWAkN1zPBd-HMyo' #YOUR_API_KEY = 'AIzaSyDjOH0xfWZXjTeVZM58WNQiCMH4DhOVJBI' #YOUR_API_KEY ='AIzaSyD2pu2vXc1RdKEqhtM8a45IZkvNW1C28Mo' #YOUR_API_KEY='AIzaSyDGjht_g-dlz7jzx-Nk_P7dOCP_nueV3vc' #YOUR_API_KEY='AIzaSyB0pZEw8T4bUFl6P43y0SBRhzMTM-dcFFk' #YOUR_API_KEY='AIzaSyA_Ncq38a38jHnJu7_OeBVPbkDrgCfLUys' #YOUR_API_KEY='AIzaSyC7O0Ec0ih55di-ozZrw-qjdbmGOIlasKI' #YOUR_API_KEY='AIzaSyDXm0-AZLr5wAFbydbN7tkhV8rEnXdxlxg' #YOUR_API_KEY='AIzaSyB3sVNAaED78fDDPqjMk4g0f4ZEaDvSMfs' #YOUR_API_KEY='AIzaSyCvCElARdCPFDjwv0ISNMmGOLQM0TWhzm8' #YOUR_API_KEY='AIzaSyCOlB9XY9vT-RbVkno5sFbgTwWhPwKT3Iw' #YOUR_API_KEY='AIzaSyCgyvrCnGQUSVAj1DtQc-gjqIeGF4rInbs' #YOUR_API_KEY='AIzaSyAUgC4RPfTR8oMgsoz6fkNzKGn43AE8JyU' #YOUR_API_KEY='AIzaSyAGpXSQ-AnAbgbxuAJ9S0aMGWQp-kB5R54' #YOUR_API_KEY='AIzaSyDO_EjeOtD8dbSlqHf5qSFiFVx8prHBHI4' #with billing #My Project 10 on csaladenes@gmail.com account YOUR_API_KEY='AIzaSyC8j2kUdpkNnA4U3YSkYWn20B-UljiPPM4' google_places = GooglePlaces(YOUR_API_KEY) # In[365]: print len(list(lists['studwhere'])) print len(UL) print len(noUL) # In[8]: query_result = google_places.text_search('Bergamo airport') if len(query_result.places)>0: place=query_result.places[0] #UL[i]={"name":place.name,"loc":place.geo_location,"id":place.place_id} # In[15]: query_result.places[0] # In[366]: for ai in range(len(list(lists['studwhere']))): i=list(lists['studwhere'])[ai] if i not in UL: if i not in noUL: print ai, #time.sleep(2) try: query_result = google_places.text_search(i.decode('utf8')) if len(query_result.places)>0: place=query_result.places[0] UL[i]={"name":place.name,"loc":place.geo_location,"id":place.place_id} else: noUL.add(i) except: print i,'|',school(i) break # In[367]: UL2={} for i in UL: UL2[i]=UL[i] UL2[i]['loc']={'lat':float(UL[i]['loc']['lat']),'lng':float(UL[i]['loc']['lng'])} file('UL.json','w').write(json.dumps(UL2)) # In[373]: noUL2=[] for i in noUL: noUL2.append(i) file('noUL.json','w').write(json.dumps(noUL2)) # In[368]: noUL # ## Studwhat # In[261]: lists['studwhat'] # # Workwhat # In[264]: lists['workwhat'] # In[340]: WL={} # In[357]: workdict=pd.read_excel('worklist.xlsx') #create reverse word dict rwd={i.replace(' ','').lower():workdict.columns[j]\ for j in range(len(workdict.columns)) for i in workdict[workdict.columns[j]].values if type(i) is not float} c=0 for i in lists['workwhat']: if 'Former ' in i:i=i[i.find('Former ')+7:] tocheck=i.replace(' ','').lower().decode('utf8') found=False for k in rwd: if k in tocheck: WL[i]=rwd[k] found=True break if not found: c+=1 print c,i,tocheck #break