Ver código fonte

crawl export data fix

zhangfan 1 mês atrás
pai
commit
8331b92040
1 arquivos alterados com 14 adições e 9 exclusões
  1. 14 9
      crossborder/export/export_all_data_sql_files.py

+ 14 - 9
crossborder/export/export_all_data_sql_files.py

@@ -1,3 +1,4 @@
+import datetime
 import time
 
 import pymysql
@@ -14,10 +15,10 @@ db_config['password'] = get_decrypted_password()
 
 # 定义查询语句和对应的目标表名
 queries = [
-    {
-        "query": "SELECT * FROM t_yujin_crossborder_prov_commodity_category",
-        "table_name": "t_yujin_crossborder_prov_commodity_category"
-    },
+    # {
+    #     "query": "SELECT * FROM t_yujin_crossborder_prov_commodity_category",
+    #     "table_name": "t_yujin_crossborder_prov_commodity_category"
+    # },
     {
         "query": "SELECT * FROM t_yujin_crossborder_prov_commodity_trade",
         "table_name": "t_yujin_crossborder_prov_commodity_trade"
@@ -37,12 +38,16 @@ MAX_RETRIES = 3   # 最大重试次数
 RETRY_DELAY = 5   # 重试间隔时间(秒)
 
 def escape_value(value):
-    """处理字段值,字符串类型添加引号并转义"""
-    if isinstance(value, str):
-        # 转义字符串内的单引号,并用单引号包裹整个字符串
-        return "'" + value.replace("'", "''") + "'"
-    else:
+    """改进版字段值处理"""
+    if value is None:
+        return 'NULL'
+    elif isinstance(value, (str, datetime.datetime, datetime.date)):
+        # return f"'{str(value).replace("'", "''")}'"
+        return "'" + str(value).replace("'", "''") + "'"
+    elif isinstance(value, (int, float)):
         return str(value)
+    else:
+        return f"'{str(value)}'"
 
 def execute_query_and_save_to_sql(query_info):
     table_name = query_info["table_name"]