Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -533,7 +533,7 @@ def send_email(job_info):
|
|
533 |
|
534 |
for key, value in job_info.items():
|
535 |
if key.endswith("time") and value:
|
536 |
-
job_info[key] =
|
537 |
|
538 |
server = smtplib.SMTP(email_serv, int(email_port))
|
539 |
# server.starttls()
|
@@ -603,19 +603,21 @@ def check_user_running_job(email, request):
|
|
603 |
|
604 |
def get_timezone_by_ip(ip):
|
605 |
try:
|
606 |
-
data = session.get(f'
|
607 |
return data['timezone']
|
608 |
except Exception:
|
609 |
return 'UTC'
|
610 |
|
611 |
|
612 |
-
def ts_to_str(
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
localized_dt = dt.astimezone(
|
|
|
|
|
619 |
return localized_dt.strftime('%Y-%m-%d %H:%M:%S (%Z)')
|
620 |
|
621 |
|
@@ -2000,7 +2002,7 @@ QALAHAYFAQYHDPDDEPVADPYDQSFESRDLLIDEWKSLTYDEVISFVPPPLDQEEMES
|
|
2000 |
'task': task,
|
2001 |
'status': 'RUNNING',
|
2002 |
'email': email,
|
2003 |
-
'ip':
|
2004 |
'cookies': dict(request.cookies),
|
2005 |
'start_time': time(),
|
2006 |
'end_time': None,
|
|
|
533 |
|
534 |
for key, value in job_info.items():
|
535 |
if key.endswith("time") and value:
|
536 |
+
job_info[key] = ts_to_str(value, get_timezone_by_ip(job_info['ip']))
|
537 |
|
538 |
server = smtplib.SMTP(email_serv, int(email_port))
|
539 |
# server.starttls()
|
|
|
603 |
|
604 |
def get_timezone_by_ip(ip):
|
605 |
try:
|
606 |
+
data = session.get(f'https://worldtimeapi.org/api/ip/{ip}').json()
|
607 |
return data['timezone']
|
608 |
except Exception:
|
609 |
return 'UTC'
|
610 |
|
611 |
|
612 |
+
def ts_to_str(timestamp, timezone):
|
613 |
+
# Create a timezone-aware datetime object from the UNIX timestamp
|
614 |
+
dt = datetime.fromtimestamp(timestamp, pytz.utc)
|
615 |
+
|
616 |
+
# Convert the timezone-aware datetime object to the target timezone
|
617 |
+
target_timezone = pytz.timezone(timezone)
|
618 |
+
localized_dt = dt.astimezone(target_timezone)
|
619 |
+
|
620 |
+
# Format the datetime object to the specified string format
|
621 |
return localized_dt.strftime('%Y-%m-%d %H:%M:%S (%Z)')
|
622 |
|
623 |
|
|
|
2002 |
'task': task,
|
2003 |
'status': 'RUNNING',
|
2004 |
'email': email,
|
2005 |
+
'ip': request.headers.get('x-forwarded-for', request.client.host),
|
2006 |
'cookies': dict(request.cookies),
|
2007 |
'start_time': time(),
|
2008 |
'end_time': None,
|