admin commited on
Commit
79f0fcf
·
1 Parent(s): 19b7019

add timestamp

Browse files
Files changed (2) hide show
  1. app.py +13 -0
  2. requirements.txt +1 -0
app.py CHANGED
@@ -3,6 +3,18 @@ import re
3
  import shutil
4
  import requests
5
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
 
8
  def download_file(url, video_id, cache_dir="./__pycache__"):
@@ -17,6 +29,7 @@ def download_file(url, video_id, cache_dir="./__pycache__"):
17
  for chunk in response.iter_content(chunk_size=8192):
18
  file.write(chunk)
19
 
 
20
  return local_file
21
 
22
 
 
3
  import shutil
4
  import requests
5
  import gradio as gr
6
+ from datetime import datetime
7
+ from zoneinfo import ZoneInfo
8
+ from tzlocal import get_localzone
9
+
10
+
11
+ def timestamp(naive_time: datetime = None, target_tz=ZoneInfo("Asia/Shanghai")):
12
+ if not naive_time:
13
+ naive_time = datetime.now()
14
+
15
+ local_tz = get_localzone()
16
+ aware_local = naive_time.replace(tzinfo=local_tz)
17
+ return aware_local.astimezone(target_tz).strftime("%Y-%m-%d %H:%M:%S")
18
 
19
 
20
  def download_file(url, video_id, cache_dir="./__pycache__"):
 
29
  for chunk in response.iter_content(chunk_size=8192):
30
  file.write(chunk)
31
 
32
+ print(f"[{timestamp()}] File was downloaded to {local_file}")
33
  return local_file
34
 
35
 
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ tzlocal