Add a to_dict method
This commit is contained in:
parent
82687980d3
commit
510bec8964
1 changed files with 35 additions and 0 deletions
35
main.py
35
main.py
|
@ -1,5 +1,6 @@
|
||||||
import calendar
|
import calendar
|
||||||
import datetime
|
import datetime
|
||||||
|
import pprint
|
||||||
|
|
||||||
from departments import DEPARTMENTS
|
from departments import DEPARTMENTS
|
||||||
from cities import CITIES
|
from cities import CITIES
|
||||||
|
@ -53,6 +54,12 @@ class InseeData:
|
||||||
return "Male"
|
return "Male"
|
||||||
return "Female"
|
return "Female"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def gender_short(self):
|
||||||
|
if self._gender == "1":
|
||||||
|
return "M"
|
||||||
|
return "F"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def city(self):
|
def city(self):
|
||||||
if self.foreign:
|
if self.foreign:
|
||||||
|
@ -113,12 +120,40 @@ class InseeData:
|
||||||
|
|
||||||
return "\n".join(message)
|
return "\n".join(message)
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
data = {
|
||||||
|
"is_valid": self.is_valid,
|
||||||
|
"gender": self.gender_short,
|
||||||
|
"month": self.month,
|
||||||
|
"year": self.year,
|
||||||
|
"order_of_birth": self.order_of_birth,
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.foreign:
|
||||||
|
data["foreigner"] = {
|
||||||
|
"countries_names": COUNTRIES.get("99" + self.country, []),
|
||||||
|
"country_code": self.country,
|
||||||
|
"continent": CONTINENTS.get(self.country[0]),
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
city = CITIES.get(self.department + self.city, dict())
|
||||||
|
data["french"] = {
|
||||||
|
"department_name": DEPARTMENTS[self.department],
|
||||||
|
"city_insee_code": self.city,
|
||||||
|
"department_code": self.department,
|
||||||
|
"city_name": city.get("name"),
|
||||||
|
"zip_code": city.get("zip_code"),
|
||||||
|
}
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# insee_number = "168127982980507"
|
# insee_number = "168127982980507"
|
||||||
insee_number = "269059913116714"
|
insee_number = "269059913116714"
|
||||||
data = InseeData(insee_number)
|
data = InseeData(insee_number)
|
||||||
print(data)
|
print(data)
|
||||||
|
pprint.pprint(data.to_dict())
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in a new issue