From 06385ba4feac0983de4bcdea71db80c0d310c94d Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Wed, 31 May 2023 11:53:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20fastapi=20=E9=87=8D?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main_old.py | 70 ----------------------------------------------------- 1 file changed, 70 deletions(-) delete mode 100644 main_old.py diff --git a/main_old.py b/main_old.py deleted file mode 100644 index 4ac1ebb..0000000 --- a/main_old.py +++ /dev/null @@ -1,70 +0,0 @@ -import requests -import pymysql -import json -import time -import re -import os - -url = "https://mnks.jxedt.com/get_question?r=0.46514869467754005&index={}" -db = pymysql.connect(host="10.10.10.100",port=3306, user="root", password="12341234", database="gofiber") -cursor = db.cursor() - -TABLE = "car" - -def loads_str(data_str): - try: - result = json.loads(data_str) - return result - except Exception as e: - error_index = re.findall(r"char (\d+)\)", str(e)) - if error_index: - error_str = data_str[int(error_index[0])] - data_str = data_str.replace(error_str, "") - # 该处将处理结果继续递归处理 - return loads_str(data_str) - -for i in range(1, 10000): - if i % 1000 == 0: - time.sleep(3) - - # 请求链接 - response = requests.get(url.format(i)) - # 加载数据,过滤escape - question_data = loads_str(response.text) - - try: - if question_data["question"] != "": - sql = "INSERT INTO %s (`id`, `question`, `options`, `image`, `answer`, `bestanswer`, `type`, `a`, `b`, `c`, `d`, `e`, `f`, `g`, `cid`) " % TABLE - sql += "VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d );" % ( - question_data["id"], - question_data["question"], - question_data["options"], - question_data["imageurl"], - question_data["ta"], - question_data["bestanswer"], - question_data["type"], - question_data["a"], - question_data["b"], - question_data["c"], - question_data["d"], - question_data["e"], - question_data["f"], - question_data["g"], - question_data["cid"], - ) - - try: - # 执行sql语句 - cursor.execute(sql) - # 提交到数据库执行 - db.commit() - except: - continue - else: - continue - except: - print("index %d 存在错误", i) - continue - -# 查询所有问题,解析,正确答案 -# SELECT id, question, IF(answer = 1,a, IF(answer = 2,b,IF(answer = 3,c,d))) as answer,bestanswer,answer as answer_id from car WHERE a != ""; \ No newline at end of file