P
P
pinguine2017-06-06 17:14:53
C++ / C#
pinguine, 2017-06-06 17:14:53

Is there any way to check the existence of a city programmatically?

Hello,
I am writing a bot for playing cities in VK and decided to implement the function of automatically adding new cities at the request of the user. At the moment, I'm using the wikipedia module, looking for words in the latter and if the word "city" occurs in the head of the article and some other keywords do not occur, I add this city. But the garbage all the same turns out to be added. For example, they added "gorgorod". The question is - is there a better way to check that the entered word is a city?

def add_new_city(city):
    try:
        inf = wikipedia.page(wikipedia.search(city + " (город)")[0])
        return "город" in inf.summary.lower() and "города" not in inf.summary.lower() \
               and "штат" not in inf.summary.lower() \
               and "тц" not in inf.summary.lower() \
               and "тк" not in inf.summary.lower() \
               and "трк" not in inf.summary.lower() \
               and "трц" not in inf.summary.lower()
    except:
        pass

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rsa97, 2018-10-04
@Conqueror3

And what? Don't they teach reading in school now?

1>c:\users\sasha\source\repos\consoleapplication1\consoleapplication1\consoleapplication1.cpp(50): error C2660: startx: function does not accept 1 arguments
1>c:\users\sasha\source\repos\consoleapplication1\consoleapplication1 \consoleapplication1.cpp(15): note: see "startx" declaration

D
Dmitry, 2017-06-06
@pinguine

https://developers.google.com/maps/documentation/g...

R
ralaton121, 2017-06-06
@ralaton121

Wikipedia doesn't list everything.
Take the base of cities.
For example, for the Russian Federation, this is a free FIAS or KLADR database. It is downloaded
from the tax website.
Or use OpenStreetMaps, Google Maps, Yandex Maps

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question