Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ import traceback
|
|
9 |
import gradio as gr
|
10 |
import requests
|
11 |
from tqdm import tqdm
|
|
|
12 |
|
13 |
lock = threading.Lock()
|
14 |
event = threading.Event()
|
@@ -189,7 +190,7 @@ def query_homework(uid, tlsysSessionId, subject, status, max_count):
|
|
189 |
headers[0].update({"Cookie": f"tlsysSessionId={tlsysSessionId}"})
|
190 |
successful = get_token()
|
191 |
if not successful:
|
192 |
-
return "
|
193 |
page_size = max_count
|
194 |
if subject == ["语文", "数学", "英语", "物理", "化学", "生物", "地理", "历史", "政治",'通用技术', '信息技术']:
|
195 |
subjects = ["-1"]
|
@@ -255,13 +256,21 @@ def parse_homework(token, include_text, homework_selection, uid):
|
|
255 |
file_list_output = [file["name"] for file in file_list]
|
256 |
global homework_downloaded_path
|
257 |
homework_downloaded_path = [file["path"] for file in file_list]
|
|
|
|
|
258 |
return gr.update(choices=file_list_output, value=[])
|
259 |
def download_file(token, homework_view):
|
260 |
download_list = []
|
261 |
for i in homework_view:
|
262 |
for j in range(len(file_list_output)):
|
263 |
if i == file_list_output[j]:
|
264 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
return download_list
|
266 |
|
267 |
with gr.Blocks(title="智学网作业获取器") as demo:
|
|
|
9 |
import gradio as gr
|
10 |
import requests
|
11 |
from tqdm import tqdm
|
12 |
+
import tempfile
|
13 |
|
14 |
lock = threading.Lock()
|
15 |
event = threading.Event()
|
|
|
190 |
headers[0].update({"Cookie": f"tlsysSessionId={tlsysSessionId}"})
|
191 |
successful = get_token()
|
192 |
if not successful:
|
193 |
+
return "获取 token 失败",""
|
194 |
page_size = max_count
|
195 |
if subject == ["语文", "数学", "英语", "物理", "化学", "生物", "地理", "历史", "政治",'通用技术', '信息技术']:
|
196 |
subjects = ["-1"]
|
|
|
256 |
file_list_output = [file["name"] for file in file_list]
|
257 |
global homework_downloaded_path
|
258 |
homework_downloaded_path = [file["path"] for file in file_list]
|
259 |
+
global homework_is_text
|
260 |
+
homework_is_text = [file["is_text"] for file in file_list]
|
261 |
return gr.update(choices=file_list_output, value=[])
|
262 |
def download_file(token, homework_view):
|
263 |
download_list = []
|
264 |
for i in homework_view:
|
265 |
for j in range(len(file_list_output)):
|
266 |
if i == file_list_output[j]:
|
267 |
+
if not homework_is_text[j]:
|
268 |
+
download_list.append(homework_downloaded_path[j])
|
269 |
+
else:
|
270 |
+
with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".txt") as f:
|
271 |
+
f.write(homework_downloaded_path[j])
|
272 |
+
temp_path = f.name
|
273 |
+
download_list.append(temp_path)
|
274 |
return download_list
|
275 |
|
276 |
with gr.Blocks(title="智学网作业获取器") as demo:
|