-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
62 lines (45 loc) · 1.35 KB
/
utils.py
File metadata and controls
62 lines (45 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
from datetime import datetime
from zoneinfo import ZoneInfo
import httpx
inter_communication_secret = os.getenv("INTER_COMMUNICATION_SECRET")
ist = ZoneInfo("Asia/Kolkata")
"""IST timezone"""
utc = ZoneInfo("UTC")
"""UTC timezone"""
async def delete_file(filename) -> str:
"""
Makes a request to delete a file from the files service
Args:
filename (str): The name of the file to delete
Returns:
(str): The response from the files service
Raises:
Exception: If the response is not successful
"""
async with httpx.AsyncClient() as client:
response = await client.post(
"http://files/delete-file",
params={
"filename": filename,
"inter_communication_secret": inter_communication_secret,
"static_file": "true",
},
)
if response.status_code != 200:
raise Exception(response.text)
return response.text
def get_utc_time() -> datetime:
"""
Current time according to UTC timezone.
Returns:
datetime: Current UTC time
"""
return datetime.now(utc)
def get_curr_time_str() -> str:
"""
Current IST time in YYYY-MM-DD HH:MM:SS format.
Returns:
str: Current IST time as a formatted string
"""
return datetime.now(ist).strftime("%Y-%m-%d %H:%M:%S")