Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 4fd7b68

Browse files
committed
feat: add sunrise and sunset localtime to output.
1 parent 5ac33ea commit 4fd7b68

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

projects/API Based Weather Report/Util_Functions.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,15 @@ def unix_timestamp_to_localtime(str_unix_timestamp, str_timezone_offset_seconds)
3131
:return: local_time (e.g., "2024-06-07 07:11:56")
3232
"""
3333
# Convert strings to integers
34-
unix_timestamp = int(str_unix_timestamp)
35-
timezone_offset_seconds = int(str_timezone_offset_seconds)
34+
try:
35+
unix_timestamp = int(str_unix_timestamp)
36+
except ValueError:
37+
return "API sunset/sunrise data error!"
38+
39+
try:
40+
timezone_offset_seconds = int(str_timezone_offset_seconds)
41+
except ValueError:
42+
return "API timezone data error!"
3643

3744
# Convert Unix timestamp to UTC datetime
3845
utc_time = datetime.utcfromtimestamp(unix_timestamp)

0 commit comments

Comments
 (0)