Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import definitions
|
| 2 |
+
import pandas as pdb
|
| 3 |
+
from typing import NamedTuple, Dict
|
| 4 |
+
|
| 5 |
+
_ROOT_DIR = definitions.get_project_root()
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class ZipCodeEntry(NamedTuple):
|
| 9 |
+
zip: str
|
| 10 |
+
city: str
|
| 11 |
+
state: str
|
| 12 |
+
lat: str
|
| 13 |
+
long: str
|
| 14 |
+
time_zone: str
|
| 15 |
+
dst_flags: bool
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def _load_zip_codes() -> Dict[str, ZipCodeEntry]:
|
| 19 |
+
df = pdb.read_csv(f'{_ROOT_DIR}/utils/us-zip-code-latitude-and-longitude.txt', dtype=str,
|
| 20 |
+
sep=';')
|
| 21 |
+
zip_code_list = {}
|
| 22 |
+
# Zip;City;State;Latitude;Longitude;Timezone;Daylight savings time flag;geopoint
|
| 23 |
+
for _, row in df.iterrows():
|
| 24 |
+
zip_code = row.get('Zip')
|
| 25 |
+
if zip_code:
|
| 26 |
+
zip_code_entry = ZipCodeEntry(
|
| 27 |
+
zip=zip_code,
|
| 28 |
+
city=row.get('City'),
|
| 29 |
+
state=row.get('State'),
|
| 30 |
+
lat=row.get('Latitude'),
|
| 31 |
+
long=row.get('Longitude'),
|
| 32 |
+
time_zone=row.get('Timezone'),
|
| 33 |
+
dst_flags=row.get('Daylight savings time flag')
|
| 34 |
+
)
|
| 35 |
+
zip_code_list[zip_code] = zip_code_entry
|
| 36 |
+
|
| 37 |
+
return zip_code_list
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
ZIP_CODE_LIST = _load_zip_codes()
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
if __name__ == '__main__':
|
| 44 |
+
print(ZIP_CODE_LIST)
|
| 45 |
+
print(ZIP_CODE_LIST.get('62833'))
|