Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 313a85d8df | |||
| 2ab29c8ef3 | |||
| 78aa8e1b75 | |||
| d8a03970f6 | |||
| b8b0295c5d | |||
| 55dd8c04f1 | |||
| 1282e46138 |
17
backend.py
17
backend.py
@@ -7,6 +7,9 @@ import zipfile
|
||||
|
||||
class Backend:
|
||||
|
||||
A1 = 130 / 60
|
||||
A2 = f"{120 * 60 / 130:.0f}s"
|
||||
|
||||
def __init__(self, db="data.db"):
|
||||
self.db_path = db
|
||||
# 先解压
|
||||
@@ -162,6 +165,7 @@ class Backend:
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def get_statistics(self):
|
||||
avg_all = self.get_avg_time()
|
||||
avg_50 = self.get_avg_time(50)
|
||||
@@ -172,12 +176,12 @@ class Backend:
|
||||
[],
|
||||
["最近50题正确率", f"{self.get_acc(50):.1f}/60%"],
|
||||
["最近100题正确率", f"{self.get_acc(120):.1f}/60%"],
|
||||
["平均耗时", f"{avg_all:.1f}/72s"],
|
||||
["预计做完用时", f"{avg_all * 1.667:.1f}/120min"],
|
||||
["50平均耗时", f"{avg_50:.1f}/72s"],
|
||||
["预计做完用时", f"{avg_50 * 1.667:.1f}/120min"],
|
||||
["120平均耗时", f"{avg_100:.1f}/72s"],
|
||||
["预计做完用时", f"{avg_100 * 1.667:.1f}/120min"],
|
||||
["平均耗时", f"{avg_all:.1f}/{self.A2}"],
|
||||
["预计做完用时", f"{avg_all * self.A1:.1f}/120min"],
|
||||
["50平均耗时", f"{avg_50:.1f}/{self.A2}"],
|
||||
["预计做完用时", f"{avg_50 * self.A1:.1f}/120min"],
|
||||
["120平均耗时", f"{avg_100:.1f}/{self.A2}"],
|
||||
["预计做完用时", f"{avg_100 * self.A1:.1f}/120min"],
|
||||
]
|
||||
return result
|
||||
|
||||
@@ -192,7 +196,6 @@ class Backend:
|
||||
|
||||
def set_config(self,a,b):
|
||||
self.title_filter = a
|
||||
|
||||
self.global_filter = ""
|
||||
if len(b)>0:
|
||||
self.global_filter = " and ( FALSE "
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
python embed.py
|
||||
7z a -tzip -mx=9 cyzg.zip main.py backend.py ./components/*.py
|
||||
del cyzg.zip
|
||||
7z a -tzip -mx=9 cyzg.zip main.py backend.py components/ -x!components/__pycache__/
|
||||
REM 7z a -tzip -mx=9 data.db.zip data.db
|
||||
timeout /t 1 >nul
|
||||
python embed.py
|
||||
gcc -Os -s main.c -o cyzg.exe -Wl,--gc-sections -Wl,--strip-all
|
||||
|
||||
@@ -211,7 +211,6 @@ class Page0(tk.Frame):
|
||||
self.text2.insert("end", self.row[14])
|
||||
self.text2.config(state="disabled")
|
||||
|
||||
correct = 0
|
||||
|
||||
for i in range(4):
|
||||
state = self.correct_answer[i] + 2 * self.my_answer[i] # 0:未选对, 1:漏选, 2:错选, 3:选对
|
||||
@@ -221,12 +220,16 @@ class Page0(tk.Frame):
|
||||
self.buttons[i].config(text=full_text, style="Miss.TButton")
|
||||
elif state == 2: # 选错 → 红色
|
||||
self.buttons[i].config(text=full_text, style="Wrong.TButton")
|
||||
correct = 1
|
||||
elif state == 3: # 选对 → 淡绿色
|
||||
self.buttons[i].config(text=full_text, style="Correct.TButton")
|
||||
else: # 未选且错误 → 不变(保持原始或默认)
|
||||
self.buttons[i].config(text=full_text, style="Default.TButton")
|
||||
|
||||
if self.my_answer == self.correct_answer:
|
||||
correct = 0 # 或者 True,表示完全正确
|
||||
else:
|
||||
correct = 1 # 表示不完全正确
|
||||
|
||||
self.c_backend.update(self.row[0], correct)
|
||||
self.winfo_toplevel().focus_set()
|
||||
|
||||
|
||||
@@ -63,7 +63,6 @@ class Page1:
|
||||
url = "https://v.zikai.wang/zikai/cyzg"
|
||||
start_pos = instructions.find(url)
|
||||
if start_pos != -1:
|
||||
# 计算起始和结束索引(tkinter 使用 "行.列" 格式)
|
||||
start_index = f"1.0 + {start_pos} chars"
|
||||
end_index = f"{start_index} + {len(url)} chars"
|
||||
|
||||
|
||||
384
crawler/get_tianyi_1.ipynb
Normal file
384
crawler/get_tianyi_1.ipynb
Normal file
@@ -0,0 +1,384 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"id": "initial_id",
|
||||
"metadata": {
|
||||
"collapsed": true,
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-08-22T00:51:15.383830Z",
|
||||
"start_time": "2025-08-22T00:51:15.162928Z"
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"import time\n",
|
||||
"\n",
|
||||
"from selenium import webdriver\n",
|
||||
"from selenium.webdriver.edge.service import Service\n",
|
||||
"from selenium.webdriver.common.by import By\n",
|
||||
"from selenium.webdriver.support.ui import WebDriverWait\n",
|
||||
"from selenium.webdriver.support import expected_conditions as EC\n",
|
||||
"from selenium.webdriver.edge.options import Options"
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": 1
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-08-22T00:51:16.137665Z",
|
||||
"start_time": "2025-08-22T00:51:16.016527Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"from bs4 import BeautifulSoup\n",
|
||||
"import sqlite3"
|
||||
],
|
||||
"id": "f184b255d5098302",
|
||||
"outputs": [],
|
||||
"execution_count": 2
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-08-22T01:24:38.259284Z",
|
||||
"start_time": "2025-08-22T01:24:38.253051Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"db_path = '../data.db'\n",
|
||||
"conn = sqlite3.connect(db_path)"
|
||||
],
|
||||
"id": "4813fcf4dea28b8d",
|
||||
"outputs": [],
|
||||
"execution_count": 54
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-08-22T01:24:21.532983Z",
|
||||
"start_time": "2025-08-22T01:24:21.528098Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": "# conn.close()",
|
||||
"id": "8ea63e4cb82fe0c",
|
||||
"outputs": [],
|
||||
"execution_count": 53
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-08-22T00:51:16.185320Z",
|
||||
"start_time": "2025-08-22T00:51:16.176280Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"edge_options = Options()\n",
|
||||
"#edge_options.add_argument(\"--headless\") # 可选:无界面模式\n",
|
||||
"edge_options.add_argument(\"--disable-gpu\")\n",
|
||||
"edge_options.add_argument(\"--no-sandbox\")\n",
|
||||
"edge_options.add_argument(\"--disable-extensions\")\n",
|
||||
"edge_options.add_argument(\"--disable-plugins\")\n",
|
||||
"edge_options.add_argument(\"--disable-popup-blocking\")\n",
|
||||
"edge_options.add_argument(\"--disable-infobars\")\n",
|
||||
"edge_options.add_argument(\"--disable-notifications\")\n",
|
||||
"edge_options.add_argument(\"--no-first-run\")\n",
|
||||
"edge_options.add_argument(\"--no-default-browser-check\")\n",
|
||||
"\n",
|
||||
"user_data_dir = r\"D:\\code\\edge\"\n",
|
||||
"edge_options.add_argument(f\"--user-data-dir={user_data_dir}\")\n",
|
||||
"# 指定配置文件(可选,默认是 Default)\n",
|
||||
"edge_options.add_argument(\"--profile-directory=Default\")"
|
||||
],
|
||||
"id": "e5632e44a52d5dc4",
|
||||
"outputs": [],
|
||||
"execution_count": 4
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-08-22T00:51:18.395Z",
|
||||
"start_time": "2025-08-22T00:51:16.198246Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"# 指定 EdgeDriver 路径(可选,若已配置环境变量可省略)\n",
|
||||
"service = Service(executable_path=r\"D:\\app\\edgeDriver\\msedgedriver.exe\")\n",
|
||||
"# 创建 Edge 浏览器实例\n",
|
||||
"driver = webdriver.Edge(service=service, options=edge_options)"
|
||||
],
|
||||
"id": "28b1479c3decc6b1",
|
||||
"outputs": [],
|
||||
"execution_count": 5
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-08-22T00:51:27.692312Z",
|
||||
"start_time": "2025-08-22T00:51:18.413131Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"driver.get(\"https://www.tianyiwangxiao.com/new/question-bank/learn-center-analyze/4d60c96ef05c452b812654e78af7701a/1957604601548296194?from=ht2\")\n",
|
||||
"\n",
|
||||
"\"https://www.tianyiwangxiao.com/new/question-bank/learn-center-analyze/94cfba022e2f4c7ebbeaa400576b3a9a/1958703246433423361?from=ht2\"\n",
|
||||
"\n",
|
||||
"# 等待页面渲染完成(例如等待 body 加载)\n",
|
||||
"wait = WebDriverWait(driver, 720)\n",
|
||||
"wait.until(EC.presence_of_element_located((By.TAG_NAME, \"body\")))\n",
|
||||
"time.sleep(3)\n",
|
||||
"\n"
|
||||
],
|
||||
"id": "779f88e1c3670c02",
|
||||
"outputs": [],
|
||||
"execution_count": 6
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-08-22T00:51:27.716520Z",
|
||||
"start_time": "2025-08-22T00:51:27.708786Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"def next_page():\n",
|
||||
" clickable_element = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, \".el-icon-right.next\")))\n",
|
||||
" clickable_element.click()\n",
|
||||
"\n",
|
||||
"def get_html():\n",
|
||||
" rendered_html = driver.page_source\n",
|
||||
" return rendered_html"
|
||||
],
|
||||
"id": "721f5a8a872bfdce",
|
||||
"outputs": [],
|
||||
"execution_count": 7
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-08-22T01:24:45.201186Z",
|
||||
"start_time": "2025-08-22T01:24:45.184772Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"def html_parser(rendered_html):\n",
|
||||
" soup = BeautifulSoup(rendered_html, 'html.parser')\n",
|
||||
"\n",
|
||||
" title = soup.find_all('p', class_='title')\n",
|
||||
"\n",
|
||||
" out_options_box = soup.find_all('div', class_='options-box')\n",
|
||||
"\n",
|
||||
" analyze = soup.find_all('div', class_='analyze')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" result={\"title\":title[0].text.strip(), \"analyze\":analyze[0].text.strip()}\n",
|
||||
"\n",
|
||||
" if (len(out_options_box)!=1):\n",
|
||||
" raise out_options_box\n",
|
||||
" out_options = out_options_box[0].find_all(\"div\",class_=\"options-item\")\n",
|
||||
"\n",
|
||||
" if len(out_options)==4:\n",
|
||||
" # 多选\n",
|
||||
" for out_option in out_options:\n",
|
||||
"\n",
|
||||
" abcd = out_option.find(\"p\",\"label\")\n",
|
||||
"\n",
|
||||
" trueFalse = False\n",
|
||||
" if \"success-active\" in abcd.get(\"class\"):\n",
|
||||
" trueFalse = True\n",
|
||||
"\n",
|
||||
" abcd = abcd.text.strip().lower()\n",
|
||||
"\n",
|
||||
" answer = out_option.find(\"p\",\"text\").text.strip()\n",
|
||||
"\n",
|
||||
" result[abcd] = [answer, trueFalse]\n",
|
||||
" else:\n",
|
||||
" # 单选\n",
|
||||
" def get_tf():\n",
|
||||
" out_options_box = soup.find_all('div', class_='answer-box')\n",
|
||||
" for i in out_options_box:\n",
|
||||
" for ii in i.find_all('div', class_='CORRECT'):\n",
|
||||
" if ii.text == \"正确\":\n",
|
||||
" return True\n",
|
||||
" elif ii.text == \"错误\":\n",
|
||||
" return False\n",
|
||||
" print(out_options_box)\n",
|
||||
" return 0\n",
|
||||
" result[\"tf\"] = get_tf()\n",
|
||||
"\n",
|
||||
" return result\n",
|
||||
"\n"
|
||||
],
|
||||
"id": "5db0bbd564c0b53f",
|
||||
"outputs": [],
|
||||
"execution_count": 55
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-08-22T01:41:12.394198Z",
|
||||
"start_time": "2025-08-22T01:41:12.386634Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"def write2db(index, result):\n",
|
||||
"\n",
|
||||
" if \"tf\" not in result:\n",
|
||||
"\n",
|
||||
" conn.execute(\n",
|
||||
" \"INSERT INTO questions (title, chapter, q_num, q_type, question, a, b, c, d, a_result, b_result, c_result, d_result, explanation) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\",\n",
|
||||
" (\n",
|
||||
" info[0],\n",
|
||||
" info[1],\n",
|
||||
" index,\n",
|
||||
" \"多选题\",\n",
|
||||
" result.get(\"title\"),\n",
|
||||
" result.get(\"a\")[0],\n",
|
||||
" result.get(\"b\")[0],\n",
|
||||
" result.get(\"c\")[0],\n",
|
||||
" result.get(\"d\")[0],\n",
|
||||
" result.get(\"a\")[1],\n",
|
||||
" result.get(\"b\")[1],\n",
|
||||
" result.get(\"c\")[1],\n",
|
||||
" result.get(\"d\")[1],\n",
|
||||
" result.get(\"analyze\"),\n",
|
||||
" )\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" else:\n",
|
||||
" if result[\"tf\"] == 0:\n",
|
||||
" return\n",
|
||||
"\n",
|
||||
" conn.execute(\n",
|
||||
" \"INSERT INTO questions (title, chapter, q_num, q_type, question, a, b, c, d, a_result, b_result, c_result, d_result, explanation) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\",\n",
|
||||
" (\n",
|
||||
" info[0],\n",
|
||||
" info[1],\n",
|
||||
" index,\n",
|
||||
" \"判断题\",\n",
|
||||
" result.get(\"title\"),\n",
|
||||
" \"\",\n",
|
||||
" \"\",\n",
|
||||
" \"\",\n",
|
||||
" \"\",\n",
|
||||
" 1 if result[\"tf\"] else 0,\n",
|
||||
" 0 if result[\"tf\"] else 1,\n",
|
||||
" \"\",\n",
|
||||
" \"\",\n",
|
||||
" result.get(\"analyze\"),\n",
|
||||
" )\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" conn.commit()"
|
||||
],
|
||||
"id": "853f278c1123cae1",
|
||||
"outputs": [],
|
||||
"execution_count": 69
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-08-22T01:46:12.973092Z",
|
||||
"start_time": "2025-08-22T01:46:12.968961Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": "info = [\"天一\",0,130]",
|
||||
"id": "71ef002122c67647",
|
||||
"outputs": [],
|
||||
"execution_count": 81
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-08-22T01:50:44.170181Z",
|
||||
"start_time": "2025-08-22T01:50:27.773842Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"for i in range(info[2]):\n",
|
||||
" p = get_html()\n",
|
||||
" result = html_parser(p)\n",
|
||||
" write2db(i, result)\n",
|
||||
" next_page()\n",
|
||||
"\n"
|
||||
],
|
||||
"id": "11d9051ab089122d",
|
||||
"outputs": [],
|
||||
"execution_count": 89
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-08-22T01:10:27.088143Z",
|
||||
"start_time": "2025-08-22T01:10:27.076521Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": "",
|
||||
"id": "ad769b774bac8989",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"<div class=\"answer CORRECT\" data-v-ee229d58=\"\">正确</div>\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": 40
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2025-08-22T01:06:54.877198Z",
|
||||
"start_time": "2025-08-22T01:06:54.867849Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": "",
|
||||
"id": "e1474fd283674850",
|
||||
"outputs": [],
|
||||
"execution_count": 35
|
||||
},
|
||||
{
|
||||
"metadata": {},
|
||||
"cell_type": "code",
|
||||
"outputs": [],
|
||||
"execution_count": null,
|
||||
"source": "",
|
||||
"id": "54ad268f864e1f6c"
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 2
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython2",
|
||||
"version": "2.7.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
BIN
data.db.zip
BIN
data.db.zip
Binary file not shown.
Reference in New Issue
Block a user