forked from daodao97/gptpdf-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
40 lines (32 loc) · 886 Bytes
/
utils.py
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
import uuid
import os
def uuid_str():
return str(uuid.uuid4())
UPLOAD_FOLDER = 'uploads'
def uploads_folder(task_id):
return os.path.join(UPLOAD_FOLDER, task_id)
def is_valid_uuid(uuid_str):
try:
uuid_obj = uuid.UUID(uuid_str, version=4)
except ValueError:
return False
return str(uuid_obj) == uuid_str
def read_file(path) -> tuple[str, bool]:
# return content, is_exist
if os.path.exists(path):
try:
with open(path, 'r', encoding='utf-8') as file:
return file.read(), True
except:
return "", False
return "", False
def write_file(path, content) -> bool:
try:
with open(path, 'w', encoding='utf-8') as file:
file.write(str(content))
return True
except:
return False
def mock_run_gptpdf(task_id):
import time
time.sleep(20)