Skip to content

Commit

Permalink
shape statements to determine contents of files
Browse files Browse the repository at this point in the history
  • Loading branch information
deronsmith committed Oct 10, 2024
1 parent a3a5a7b commit 79c7d14
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions modules/hms/locate_timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
logger.setLevel(logging.DEBUG)

tz_df = None
tz_list = None
if os.path.exists(r"/src/hms_flask/modules/hms/tz_files/tz_world.dbf"):
if os.path.exists(r"/src/hms_flask/modules/hms/tz_files/tzinfo_updated.csv"):
tz_df = pd.read_csv(r"/src/hms_flask/modules/hms/tz_files/tz_world.dbf", names=("TZID", "TZName", "TZOffset", "TZOffsetDST"))
else:
tz_list = os.path.join(os.path.realpath(__file__), "..", "tz_files", "tzinfo_updated.csv")
Expand All @@ -28,14 +27,15 @@


def get_timezone(latitude, longitude):
logger.info("TZ_DF: " + str(tz_df))
logger.info("TZ_LIST: " + str(tz_list))
print("TZ_DF: " + str(tz_df.shape))
print("TZ_dbf: " + str(tz_gdf.shape))
tz_point = Point(float(longitude), float(latitude))
gdf = tz_gdf[tz_gdf.contains(tz_point)]
if gdf.empty:
return json.dumps({"error": "No timezone found for the given coordinates"})
tz_name = gdf['TZID'].values[0]
tz_offset = tz_df[tz_df["TZName"] == tz_name]["TZOffset"].values[0].split(":")[0]
tz_offset = tz_df[tz_df["TZName"] == tz_name]["TZOffset"]
tz_offset = tz_offset.values[0].split(":")[0]
timezone_details = {"latitude": float(latitude), "longitude": float(longitude), "tzName": str(tz_name), "tzOffset": int(tz_offset)}
logger.info(f"Timezone details: {timezone_details}")
return timezone_details

0 comments on commit 79c7d14

Please sign in to comment.