def test_countries(self): text = """That was fertile ground for the emergence of various forms of totalitarian governments such as Japan, Italy, and Germany, as well as other countries""" result = geotext.GeoText(text).countries expected = ['Japan', 'Italy', 'Germany'] self.assertEqual(result, expected)
def convert_location_to_coords_so(cursor: sqlite3.Cursor, location_data): geolocator = Nominatim(user_agent="my geo_so agent") for job in location_data: places = gt.GeoText(job['description']) loc = geolocator.geocode(places.cities) if loc == ("remote" or "Remote") or loc is None: print("No location provided") continue else: job_lat = loc.latitude job_long = loc.latitude job_id = job['id'] cursor.execute(f'''INSERT INTO coords_of_jobs(id, latitude, longitude) VALUES (?,?,?)''', (job_id, job_lat, job_long))
def process(self, tup): clean_text = ' '.join(w for w in self._get_words(tup.values[0])) places = geotext.GeoText(clean_text) now_minute = self._get_minute() now_hour = now_minute.replace(minute=0) for city in places.cities: city = city.lower() if city in self.stop_cities: continue log.info('Updating count: %s, %s, %s', now_hour, now_minute, city) self.db.cities.minute.update( { 'hour': now_hour, 'minute': now_minute, 'city': city }, {'$inc': { 'count' : 1 } }, upsert=True)
def fetch(owner, repo, lastId="", countries={}, count=0): client = GraphQLClient('https://api.github.com/graphql') # https://github.com/settings/tokens client.inject_token("bearer {}".format(os.environ['GITHUB_TOKEN'])) try: response = client.execute(QUERY_WITH_CUSOR, { "owner": owner, "name": repo, "lastId": lastId }) if len(lastId) > 0 else client.execute(QUERY, { "owner": owner, "name": repo }) except urllib.error.URLError: return sorted(countries.items(), key=operator.itemgetter(1), reverse=True) source = json.loads(response) if source.get('errors'): print(source['errors']) raise Exception() edges = source['data']['repository']['stargazers']['edges'] if len(edges) == 0: return sorted(countries.items(), key=operator.itemgetter(1), reverse=True) cursor = edges.pop()['cursor'] text = geotext.GeoText(response) for code in text.country_mentions: cc = text.country_mentions.get(code) countries[code] = countries[code] + cc if countries.get(code) else cc # time.sleep(1) print("[{}] {}/{} {}".format(count, owner, repo, lastId)) return fetch(owner, repo, cursor, countries, count + 1)
def test_nationalities(self): text = 'Japanese people like anime. French people often drink wine. Chinese people enjoy fireworks.' result = geotext.GeoText(text).nationalities expected = ['Japanese', 'French', 'Chinese'] self.assertEqual(result, expected)
def test_cities(self): text = """São Paulo é a capital do estado de São Paulo. As cidades de Barueri e Carapicuíba fazem parte da Grade São Paulo. O Rio de Janeiro continua lindo. No carnaval eu vou para Salvador. No reveillon eu quero ir para Santos.""" result = geotext.GeoText(text).cities expected = [ 'São Paulo', 'São Paulo', 'Barueri', 'Carapicuíba', 'Rio de Janeiro', 'Salvador', 'Santos' ] self.assertEqual(result, expected) brazillians_northeast_capitals = """As capitais do nordeste brasileiro são: Salvador na Bahia, Recife em Pernambuco, Natal fica no Rio Grande do Norte, João Pessoa fica na Paraíba, Fortaleza fica no Ceará, Teresina no Piauí, Aracaju em Sergipe, Maceió em Alagoas e São Luís no Maranhão.""" result = geotext.GeoText(brazillians_northeast_capitals).cities # PS: 'Rio Grande' is not a northeast city, but is a brazilian city expected = [ 'Salvador', 'Recife', 'Natal', 'Rio Grande', 'João Pessoa', 'Fortaleza', 'Teresina', 'Aracaju', 'Maceió', 'São Luís' ] self.assertEqual(result, expected) brazillians_north_capitals = """As capitais dos estados do norte brasileiro são: Manaus no Amazonas, Palmas em Tocantins, Belém no Pará, Acre no Rio Branco.""" result = geotext.GeoText(brazillians_north_capitals).cities expected = ['Manaus', 'Palmas', 'Belém', 'Rio Branco'] self.assertEqual(result, expected) brazillians_southeast_capitals = """As capitais da região sudeste do Brasil são: Rio de Janeiro no Rio de Janeiro, São Paulo em São Paulo, Belo Horizonte em Minas Gerais, Vitória no Espírito Santo""" result = geotext.GeoText(brazillians_southeast_capitals).cities # 'Rio de Janeiro' and 'Sao Paulo' city and state name are the same, so appears 2 times, it's ok! expected = [ 'Rio de Janeiro', 'Rio de Janeiro', 'São Paulo', 'São Paulo', 'Belo Horizonte', 'Vitória' ] self.assertEqual(result, expected) brazillians_central_capitals = """As capitais da região centro-oeste do Brasil são: Goiânia em Goiás, Brasília no Distrito Federal, Campo Grande no Mato Grosso do Sul, Cuiabá no Mato Grosso.""" result = geotext.GeoText(brazillians_central_capitals).cities expected = ['Goiânia', 'Goiás', 'Brasília', 'Campo Grande', 'Cuiabá'] self.assertEqual(result, expected) brazillians_south_capitals = """As capitais da região sul são: Porto Alegre no Rio Grande do Sul, Floripa em Santa Catarina, Curitiba no Paraná""" result = geotext.GeoText(brazillians_south_capitals).cities # PS: 'Rio Grande' is not a south city, but is a brazilian city expected = [ 'Porto Alegre', 'Rio Grande', 'Santa Catarina', 'Curitiba', 'Paraná' ] self.assertEqual(result, expected) result = geotext.GeoText('Rio de Janeiro y Havana', 'BR').cities expected = ['Rio de Janeiro'] self.assertEqual(result, expected)
def test_country_mentions(self): text = 'I would like to visit Lima, Dublin and Moscow (Russia).' result = geotext.GeoText(text).country_mentions expected = {'PE': 1, 'IE': 1, 'RU': 2} self.assertEqual(result, expected)
def main(): while True: a = listen() if 'how are you' in a.lower(): speak("i'm fine how are you ") elif 'hello' in a.lower(): speak('hello tell me what can i do for you') elif 'time' in a.lower(): now = datetime.datetime.now() a = now.strftime("%H:%M:%S") speak(a) elif 'weather' in a: try: cit = geotext.GeoText(a).cities con = geotext.GeoText(a).countries if not cit == []: speak(wharth(cit[0])) elif not con == []: speak(wharth(con[0])) else: speak(wharth(loc())) except: city = loc() speak(wharth(city)) elif ('who created you' in a.lower()) or ('your creator name' in a.lower()) or ( 'your father name' in a.lower()) or ("tell me your creator name" in a.lower()) or 'creator' in a.lower(): speak( 'MY CREATER IS G S AASHISH \n he created me on fourteenth april 2020 .........one very important fact on this day prime minister Shri Narender Modi of india announced extention of quarantine holiday due to COVID-19 till 3rd may in his ten A.M. speech \n my creater created me in quarantine holidays' ) elif 'open spotify' in a.lower(): url = "https://open.spotify.com" webbrowser.open(url) speak("opening spotify") elif 'prateek kuhad song' in a.lower( ) or 'prateek kuhad songs' in a.lower(): url = "https://open.spotify.com/artist/0tC995Rfn9k2l7nqgCZsV7" webbrowser.open(url) speak("opening spotify") elif 'my mother name' in a: speak('Your Mother Name is Sadhna Lal') speak('Now she will give you 100 rupees') elif 'open sapne song' in a.lower() or 'sapna song' in a.lower(): url = "https://www.youtube.com/watch?v=UQoQRiOGqVg" webbrowser.open(url) speak("opening Sapne song by MO JOJO youtube") elif 'open youtube' in a.lower(): url = "https://www.youtube.com" webbrowser.open(url) speak("opening youtube") elif 'open youtube' in a.lower(): url = "https://www.google.com" webbrowser.open(url) speak("opening youtube") elif 'date' in a.lower(): data_date() elif 'close opera' in a.lower(): closeOpera() speak("closing opera") time.sleep(5) elif 'wikipedia' in a.lower(): a = a.replace('wikipedia', '') print("new:", a) speak(wiki(a)) elif 'play song' in a.lower(): url = "https: // open.spotify.com / artist / 3Y5nIabMJLTsWgW6Jqdn7n" webbrowser.open(url) speak("opening spotify") elif 'she can' in a.lower(): url = "https://www.youtube.com/watch?v=uj6pLKl2wU0" webbrowser.open(url) speak("opening youtube") elif 'exit' in a.lower() or 'sleep' in a.lower() or 'stop' in a.lower( ) or 'close' in a.lower(): speak('going on sleep') break elif 'jor se bolo' in a.lower(): speak('jai MATA di') print('\t \t \t jai mata dii 🚩🚩🚩🚩🚩🚩') elif a == "l": continue elif 'who lives in your heart' in a.lower(): speak('Shri Ram Jaanki Baithee Hain Mere Seene Mein') speak('jai shri ram ') print('\t\t\t jai shri ram🚩🚩🚩🚩🚩🚩') elif 'do i have' in a.lower(): SERVICE = authenticate_google() text = a.lower() try: c = get_events(get_date(text), SERVICE) if c == 'No upcoming events found.': speak("you don't have any event") else: speak('you have following events:') speak(c) except: speak( "sorry i could not able to hear your complete command say it again please!!" ) else: speak("can't able to perform this task") return main()