meteociel.cities.get_city
- meteociel.cities.get_city(target_name: str, *, keys: dict = None, max_delta: int = 2)
Search in the database for a targeted city. All the cities whose names contains
target_namewill match. Furthermore, please note that the cities’ is arestrinstance.Warning
You must generate a database before using
get_city.Tip
You can pass
""as name to match all cities.Parameters
- target_name
str The name of the city you are looking for.
- keys
dict, keyword-only, optionnal By default:
{}. In addition to the name akeysdictionnary can be given to restrict research. The items ofkeysmust match the items of the cities database.- max_delta
int, keyword-only, optionnal By default
2. The maximum delta allowed when comparing the searched name with the names in the database. The highermax_deltais, the higher the tolerance to typing errors will be, and the more likely a search will return many results.
Returns
- match
dict The dictionnary that contains the cities that matched the search.
Raises
- FileNotFoundError
This exception is raised if database doesn’t exist. In that case, check the spelling of
cities.DATABASE_NAMEif you are using a custom one or generate a database by callingcities.generate_database().- CityNotFoundError
Raised if the requested city has not been found in the database.
Exemples
>>> import json >>> from meteociel.cities import get_city >>> matches = get_city("Ajaccio") >>> json.dumps(matches, indent=4) { "7761": { "names": [ "ajaccio - campo dell'oro", "ajaccio" ], "has-sounding": true, "has-station": true, "station-type": "synop", "country": "france" }, "7752": { ... }, "20004014": { ... } } >>> matches = get_city("Ajaccio", keys={"has-sounding": True}) >>> json.dumps(matches, indent=4) { "7761": { "names": [ "ajaccio", "ajaccio - campo dell'oro" ], "has-sounding": true, "has-station": true, "station-type": "synop" "country": "france" } }
- target_name