mdbq 3.7.11__py3-none-any.whl → 3.7.13__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mdbq/config/default.py +2 -2
- mdbq/config/myconfig.py +5 -3
- mdbq/mysql/mysql.py +1 -24
- mdbq/redis/getredis.py +1 -1
- {mdbq-3.7.11.dist-info → mdbq-3.7.13.dist-info}/METADATA +1 -1
- {mdbq-3.7.11.dist-info → mdbq-3.7.13.dist-info}/RECORD +8 -8
- {mdbq-3.7.11.dist-info → mdbq-3.7.13.dist-info}/WHEEL +0 -0
- {mdbq-3.7.11.dist-info → mdbq-3.7.13.dist-info}/top_level.txt +0 -0
mdbq/config/default.py
CHANGED
mdbq/config/myconfig.py
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
# -*- coding: UTF-8 –*-
|
2
2
|
import os
|
3
|
+
import sys
|
3
4
|
import json
|
4
|
-
from mdbq.config import set_support
|
5
|
+
# from mdbq.config import set_support
|
5
6
|
"""
|
6
7
|
用来读取本地配置文件
|
7
8
|
"""
|
9
|
+
support_path = os.path.join(os.path.realpath(os.path.dirname(sys.argv[0])), 'support')
|
8
10
|
|
9
11
|
|
10
12
|
def main():
|
11
|
-
support_path = set_support.SetSupport(dirname='support').dirname
|
13
|
+
# support_path = set_support.SetSupport(dirname='support').dirname
|
12
14
|
file = os.path.join(support_path, 'my_config.txt')
|
13
15
|
if not os.path.isfile(file):
|
14
16
|
print(f'缺少配置文件,无法读取配置文件: {file}')
|
@@ -20,7 +22,7 @@ def main():
|
|
20
22
|
|
21
23
|
def write_back(datas):
|
22
24
|
""" 将数据写回本地 """
|
23
|
-
support_path = set_support.SetSupport(dirname='support').dirname
|
25
|
+
# support_path = set_support.SetSupport(dirname='support').dirname
|
24
26
|
file = os.path.join(support_path, 'my_config.txt')
|
25
27
|
with open(file, 'w+', encoding='utf-8') as f:
|
26
28
|
json.dump(datas, f, ensure_ascii=False, sort_keys=False, indent=4)
|
mdbq/mysql/mysql.py
CHANGED
@@ -172,8 +172,6 @@ class MysqlUpload:
|
|
172
172
|
__res_dict.update({k: 'INT'})
|
173
173
|
elif count_float > 0:
|
174
174
|
if count_int + count_float > 10:
|
175
|
-
# if count_float > 5:
|
176
|
-
# v = round(float(v), 4)
|
177
175
|
if count_float >= 6:
|
178
176
|
__res_dict.update({k: 'decimal(14,6)'})
|
179
177
|
else:
|
@@ -207,8 +205,6 @@ class MysqlUpload:
|
|
207
205
|
if '数据主体' not in dict_data.keys():
|
208
206
|
logger.info(f'dict_data 中"数据主体"键不能为空')
|
209
207
|
return
|
210
|
-
|
211
|
-
# connection = pymysql.connect(**self.config) # 连接数据库
|
212
208
|
connection = self.keep_connect(_db_name=db_name, _config=self.config, max_try=10)
|
213
209
|
if not connection:
|
214
210
|
return
|
@@ -229,7 +225,6 @@ class MysqlUpload:
|
|
229
225
|
logger.info(f"创建Database: {db_name}")
|
230
226
|
|
231
227
|
self.config.update({'database': db_name}) # 添加更新 config 字段
|
232
|
-
# connection = pymysql.connect(**self.config) # 重新连接数据库
|
233
228
|
connection = self.keep_connect(_db_name=db_name, _config=self.config, max_try=10)
|
234
229
|
if not connection:
|
235
230
|
return
|
@@ -282,7 +277,6 @@ class MysqlUpload:
|
|
282
277
|
for up_col in remove_by_key:
|
283
278
|
condition += [f'`{up_col}` = "{dict_data[up_col]}"']
|
284
279
|
condition = ' AND '.join(condition)
|
285
|
-
# logger.info(condition)
|
286
280
|
sql = f"SELECT {se_key} FROM `{table_name}` WHERE {condition}"
|
287
281
|
cursor.execute(sql)
|
288
282
|
result = cursor.fetchall()
|
@@ -299,7 +293,6 @@ class MysqlUpload:
|
|
299
293
|
cols = ', '.join([cols, '数据主体'])
|
300
294
|
binary_data = dict_data['数据主体']
|
301
295
|
sql = f"INSERT INTO `{table_name}` ({cols}) VALUES ({values}, %s)"
|
302
|
-
# logger.info(sql)
|
303
296
|
cursor.execute(sql, binary_data)
|
304
297
|
else:
|
305
298
|
sql = f"""INSERT INTO `{table_name}` (数据主体) VALUES (%s);"""
|
@@ -319,17 +312,14 @@ class MysqlUpload:
|
|
319
312
|
column_name = 'id'
|
320
313
|
sql = (f'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS '
|
321
314
|
f'WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s')
|
322
|
-
# cursor.execute(f"SHOW COLUMNS FROM `{table_name}` LIKE 'id'")
|
323
315
|
cursor.execute(sql, (db_name, table_name, column_name))
|
324
316
|
result = cursor.fetchone()
|
325
317
|
if result:
|
326
|
-
# cursor.execute(f"ALTER TABLE `{table_name}` DROP COLUMN id;") # 删除 id 列
|
327
318
|
sql = f"ALTER TABLE `{table_name}` DROP COLUMN {column_name}" # 删除 id 列
|
328
319
|
cursor.execute(sql)
|
329
320
|
cursor.execute(
|
330
321
|
f"ALTER TABLE `{table_name}` ADD column id INT AUTO_INCREMENT PRIMARY KEY FIRST;")
|
331
322
|
cursor.execute(f"ALTER TABLE `{table_name}` AUTO_INCREMENT = 1") # 设置自增从 1 开始
|
332
|
-
# logger.info(f'重置自增id')
|
333
323
|
else:
|
334
324
|
logger.info(f'{table_name} 存在复合主键: 存在复合主键: {[item['PrimaryKey'] for item in result]}, 无法重置自增id')
|
335
325
|
except Exception as e:
|
@@ -1434,7 +1424,7 @@ class OptimizeDatas:
|
|
1434
1424
|
connection = pymysql.connect(**_config) # 连接数据库
|
1435
1425
|
return connection
|
1436
1426
|
except Exception as e:
|
1437
|
-
logger.error(f'连接失败,正在重试: {attempts}/{max_try} {e}')
|
1427
|
+
logger.error(f'{_db_name}连接失败,正在重试: {self.host}:{self.port} {attempts}/{max_try} {e}')
|
1438
1428
|
attempts += 1
|
1439
1429
|
time.sleep(30)
|
1440
1430
|
logger.error(f'{_db_name}: 连接失败,重试次数超限,当前设定次数: {max_try}')
|
@@ -1479,16 +1469,12 @@ class OptimizeDatas:
|
|
1479
1469
|
logger.info(f'mysql({self.host}: {self.port}) {self.db_name} 数据库优化中(日期长度: {self.days} 天)...')
|
1480
1470
|
for table_dict in tables:
|
1481
1471
|
for key, table_name in table_dict.items():
|
1482
|
-
# if '店铺指标' not in table_name:
|
1483
|
-
# continue
|
1484
1472
|
self.config.update({'database': self.db_name}) # 添加更新 config 字段
|
1485
|
-
# self.connection = pymysql.connect(**self.config)
|
1486
1473
|
self.connection = self.keep_connect(_db_name=self.db_name, _config=self.config, max_try=10)
|
1487
1474
|
if not self.connection:
|
1488
1475
|
return
|
1489
1476
|
with self.connection.cursor() as cursor:
|
1490
1477
|
sql = f"SELECT 1 FROM `{table_name}` LIMIT 1"
|
1491
|
-
# logger.info(sql)
|
1492
1478
|
cursor.execute(sql)
|
1493
1479
|
result = cursor.fetchone()
|
1494
1480
|
if not result:
|
@@ -1509,7 +1495,6 @@ class OptimizeDatas:
|
|
1509
1495
|
max_result = cursor.fetchone()
|
1510
1496
|
cursor.execute(sql_min)
|
1511
1497
|
min_result = cursor.fetchone()
|
1512
|
-
# logger.info(min_result['min_date'], max_result['max_date'])
|
1513
1498
|
# 匹配修改为合适的起始和结束日期
|
1514
1499
|
if self.start_date < pd.to_datetime(min_result['min_date']):
|
1515
1500
|
self.start_date = pd.to_datetime(min_result['min_date'])
|
@@ -1537,17 +1522,14 @@ class OptimizeDatas:
|
|
1537
1522
|
column_name = 'id'
|
1538
1523
|
sql = (f'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS '
|
1539
1524
|
f'WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s')
|
1540
|
-
# cursor.execute(f"SHOW COLUMNS FROM `{table_name}` LIKE 'id'")
|
1541
1525
|
cursor.execute(sql, (self.db_name, table_name, column_name))
|
1542
1526
|
result = cursor.fetchone()
|
1543
1527
|
if result:
|
1544
|
-
# cursor.execute(f"ALTER TABLE `{table_name}` DROP COLUMN id;") # 删除 id 列
|
1545
1528
|
sql = f"ALTER TABLE `{table_name}` DROP COLUMN {column_name}" # 删除 id 列
|
1546
1529
|
cursor.execute(sql)
|
1547
1530
|
cursor.execute(
|
1548
1531
|
f"ALTER TABLE `{table_name}` ADD column id INT AUTO_INCREMENT PRIMARY KEY FIRST;")
|
1549
1532
|
cursor.execute(f"ALTER TABLE `{table_name}` AUTO_INCREMENT = 1") # 设置自增从 1 开始
|
1550
|
-
# logger.info(f'重置自增id')
|
1551
1533
|
else:
|
1552
1534
|
logger.info(f'{table_name} 存在复合主键: {[item['PrimaryKey'] for item in result]}, 无法重置自增id')
|
1553
1535
|
except Exception as e:
|
@@ -1634,7 +1616,6 @@ class OptimizeDatas:
|
|
1634
1616
|
|
1635
1617
|
def database_list(self):
|
1636
1618
|
""" 获取所有数据库 """
|
1637
|
-
# connection = pymysql.connect(**self.config) # 连接数据库
|
1638
1619
|
connection = self.keep_connect(_db_name=self.db_name, _config=self.config, max_try=10)
|
1639
1620
|
if not connection:
|
1640
1621
|
return
|
@@ -1646,7 +1627,6 @@ class OptimizeDatas:
|
|
1646
1627
|
|
1647
1628
|
def table_list(self, db_name):
|
1648
1629
|
""" 获取指定数据库的所有数据表 """
|
1649
|
-
# connection = pymysql.connect(**self.config) # 连接数据库
|
1650
1630
|
connection = self.keep_connect(_db_name=self.db_name, _config=self.config, max_try=10)
|
1651
1631
|
if not connection:
|
1652
1632
|
return
|
@@ -1664,7 +1644,6 @@ class OptimizeDatas:
|
|
1664
1644
|
connection.close() # 断开连接
|
1665
1645
|
|
1666
1646
|
self.config.update({'database': db_name}) # 添加更新 config 字段
|
1667
|
-
# connection = pymysql.connect(**self.config) # 重新连接数据库
|
1668
1647
|
connection = self.keep_connect(_db_name=db_name, _config=self.config, max_try=10)
|
1669
1648
|
if not connection:
|
1670
1649
|
return
|
@@ -1679,7 +1658,6 @@ class OptimizeDatas:
|
|
1679
1658
|
获取指定数据表的数据, 按天获取
|
1680
1659
|
"""
|
1681
1660
|
self.config.update({'database': db_name}) # 添加更新 config 字段
|
1682
|
-
# connection = pymysql.connect(**self.config)
|
1683
1661
|
connection = self.keep_connect(_db_name=db_name, _config=self.config, max_try=10)
|
1684
1662
|
if not connection:
|
1685
1663
|
return
|
@@ -1715,7 +1693,6 @@ class OptimizeDatas:
|
|
1715
1693
|
for table_dict in tables:
|
1716
1694
|
for key, table_name in table_dict.items():
|
1717
1695
|
self.config.update({'database': self.db_name}) # 添加更新 config 字段
|
1718
|
-
# self.connection = pymysql.connect(**self.config)
|
1719
1696
|
self.connection = self.keep_connect(_db_name=self.db_name, _config=self.config, max_try=10)
|
1720
1697
|
if not self.connection:
|
1721
1698
|
return
|
mdbq/redis/getredis.py
CHANGED
@@ -23,7 +23,7 @@ if platform.system() == 'Windows':
|
|
23
23
|
else:
|
24
24
|
D_PATH = os.path.join(os.path.realpath(os.path.dirname(sys.argv[0])), 'Downloads')
|
25
25
|
if not os.path.exists(D_PATH):
|
26
|
-
os.
|
26
|
+
os.makedirs(D_PATH)
|
27
27
|
|
28
28
|
m_engine, username, password, host, port = default.get_mysql_engine(platform='Windows', hostname='xigua_lx', sql='mysql', local='remoto', config_file=None)
|
29
29
|
|
@@ -7,8 +7,8 @@ mdbq/aggregation/query_data.py,sha256=jGKnHm9vRlKCZeIdP15lgpASKaQgoQjPZyd2IsTJY6
|
|
7
7
|
mdbq/bdup/__init__.py,sha256=AkhsGk81SkG1c8FqDH5tRq-8MZmFobVbN60DTyukYTY,28
|
8
8
|
mdbq/bdup/bdup.py,sha256=hJs815hGFwm_X5bP2i9XugG2w2ZY_F0n3-Q0hVpIPPw,4892
|
9
9
|
mdbq/config/__init__.py,sha256=jso1oHcy6cJEfa7udS_9uO5X6kZLoPBF8l3wCYmr5dM,18
|
10
|
-
mdbq/config/default.py,sha256=
|
11
|
-
mdbq/config/myconfig.py,sha256=
|
10
|
+
mdbq/config/default.py,sha256=LEDVIBR6aEG5iTKgNzNHOPEujVxp6MF-1i7TwqMM2BI,5092
|
11
|
+
mdbq/config/myconfig.py,sha256=IEJOYoSiDivplE6N-1UWuVKUj6zLa4EOsuj3aONb85g,1000
|
12
12
|
mdbq/config/products.py,sha256=FbBIqmyaiq9h03FIeE9W2bwbLm2_5pr6xyzPV-u7Ges,5689
|
13
13
|
mdbq/config/set_support.py,sha256=eM2scqDzGNR2kkbYmguRB2ucrqeX0KMh5OMIaGsLem4,877
|
14
14
|
mdbq/dataframe/__init__.py,sha256=2HtCN8AdRj53teXDqzysC1h8aPL-mMFy561ESmhehGQ,22
|
@@ -18,7 +18,7 @@ mdbq/log/mylogger.py,sha256=oaT7Bp-Hb9jZt52seP3ISUuxVcI19s4UiqTeouScBO0,3258
|
|
18
18
|
mdbq/log/spider_logging.py,sha256=cTI9BHePz9Q4QThc_OBxTLqX5tF9iPwIQ-dASpf6zCA,2142
|
19
19
|
mdbq/mongo/__init__.py,sha256=SILt7xMtQIQl_m-ik9WLtJSXIVf424iYgCfE_tnQFbw,13
|
20
20
|
mdbq/mysql/__init__.py,sha256=A_DPJyAoEvTSFojiI2e94zP0FKtCkkwKP1kYUCSyQzo,11
|
21
|
-
mdbq/mysql/mysql.py,sha256=
|
21
|
+
mdbq/mysql/mysql.py,sha256=bsv-khT7fyoYxEJMbJPks-V1tYvwX-mNHsoTNXfWiKk,95884
|
22
22
|
mdbq/mysql/s_query.py,sha256=pj5ioJfUT81Su9S-km9G49gF5F2MmXXfw_oAIUzhN28,8794
|
23
23
|
mdbq/mysql/year_month_day.py,sha256=VgewoE2pJxK7ErjfviL_SMTN77ki8GVbTUcao3vFUCE,1523
|
24
24
|
mdbq/other/__init__.py,sha256=jso1oHcy6cJEfa7udS_9uO5X6kZLoPBF8l3wCYmr5dM,18
|
@@ -31,10 +31,10 @@ mdbq/pbix/pbix_refresh.py,sha256=JUjKW3bNEyoMVfVfo77UhguvS5AWkixvVhDbw4_MHco,239
|
|
31
31
|
mdbq/pbix/refresh_all.py,sha256=OBT9EewSZ0aRS9vL_FflVn74d4l2G00wzHiikCC4TC0,5926
|
32
32
|
mdbq/pbix/refresh_all_old.py,sha256=_pq3WSQ728GPtEG5pfsZI2uTJhU8D6ra-htIk1JXYzw,7192
|
33
33
|
mdbq/redis/__init__.py,sha256=YtgBlVSMDphtpwYX248wGge1x-Ex_mMufz4-8W0XRmA,12
|
34
|
-
mdbq/redis/getredis.py,sha256=
|
34
|
+
mdbq/redis/getredis.py,sha256=eK5eGpJFS50urJdludRuNhCVcvWvn98Bw_8eZN1oTN0,25733
|
35
35
|
mdbq/spider/__init__.py,sha256=RBMFXGy_jd1HXZhngB2T2XTvJqki8P_Fr-pBcwijnew,18
|
36
36
|
mdbq/spider/aikucun.py,sha256=HK6x0MnpUN1jUSWnLQ_UEH2QSYcLFBGhhUBD3FVwrzY,21840
|
37
|
-
mdbq-3.7.
|
38
|
-
mdbq-3.7.
|
39
|
-
mdbq-3.7.
|
40
|
-
mdbq-3.7.
|
37
|
+
mdbq-3.7.13.dist-info/METADATA,sha256=4pQx2WlX2uZDe5YOqTsnHfdXymjn1HhLkJP7Ocn5SdU,244
|
38
|
+
mdbq-3.7.13.dist-info/WHEEL,sha256=cpQTJ5IWu9CdaPViMhC9YzF8gZuS5-vlfoFihTBC86A,91
|
39
|
+
mdbq-3.7.13.dist-info/top_level.txt,sha256=2FQ-uLnCSB-OwFiWntzmwosW3X2Xqsg0ewh1axsaylA,5
|
40
|
+
mdbq-3.7.13.dist-info/RECORD,,
|
File without changes
|
File without changes
|