fabiocaccamo / python-codicefiscale

:it: :credit_card: italian fiscal codes encoding, decoding and validation - codifica, decodifica e validazione del Codice Fiscale italiano.
MIT License
71 stars 24 forks source link

Get all cities/nations names #127

Closed TeoLucco closed 10 months ago

TeoLucco commented 11 months ago

Crate a method or a property which returns all cities and nations names, in order to have all accepted options for a birth city field

Upvote & Fund

Fund with Polar

fabiocaccamo commented 10 months ago

@TeoLucco this is a useful feature, I think that having a list of dicts with name and slug would be better, do you agree?

TeoLucco commented 10 months ago

I agree, a list of dictionaries with name and slug would be perfect!

fabiocaccamo commented 10 months ago

@TeoLucco what do you think about duplicated entries?

Very often the same municipality is listed multiple times because they changed along the time, (eg. they changed the province they belong to and consequently also their code changed).

I'm starting to think that this is much more complicated than expected.

TeoLucco commented 10 months ago

I'd recommend using a HashSet instead of a simple list. For my specific use case, which involves inputting a city name and using it with other fields to call the encode function and check for the matching fiscal code, the code might not be necessary. I plan to use this HashSet to list possible values for the "birthday" field in a Django model, which will be reused in a form with autocomplete functionality.

fabiocaccamo commented 10 months ago

@TeoLucco the data comes from here: https://github.com/fabiocaccamo/python-codicefiscale/blob/main/codicefiscale/data/municipalities.json

TeoLucco commented 10 months ago

Do you know which is the meaning of all name fields(name, name_alt, name_alt_trans ecc..)?there are a lot!

fabiocaccamo commented 10 months ago

Indeed, I did it:

active: indicates if the municipality is still active or not code: the municipality code date_created: when the municipality has been "created" date_deleted: when the municipality has been "deleted", if empty, it means it's still active name: the official name name_alt: possible alternative name name_alt_trans: possible alternative name translated, sometimes some cities have bilingual name name_slugs: slugs computed from all name_* for indexing name_trans: the official name translated (often it's empty) province: the province the municipality belongs to

fabiocaccamo commented 10 months ago

@TeoLucco you can import methods from the data module to use raw data for your specific needs.