mdbq 3.8.2__py3-none-any.whl → 3.8.4__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/__version__.py +1 -3
- mdbq/aggregation/query_data.py +52 -4
- mdbq/log/spider_logging.py +4 -5
- mdbq/other/download_sku_picture.py +3 -1
- mdbq/redis/getredis.py +2 -1
- mdbq/spider/aikucun.py +3 -2
- {mdbq-3.8.2.dist-info → mdbq-3.8.4.dist-info}/METADATA +1 -1
- {mdbq-3.8.2.dist-info → mdbq-3.8.4.dist-info}/RECORD +10 -12
- mdbq/aggregation/optimize_data_bak.py +0 -30
- mdbq/pbix/refresh_all_old.py +0 -177
- {mdbq-3.8.2.dist-info → mdbq-3.8.4.dist-info}/WHEEL +0 -0
- {mdbq-3.8.2.dist-info → mdbq-3.8.4.dist-info}/top_level.txt +0 -0
mdbq/__version__.py
CHANGED
mdbq/aggregation/query_data.py
CHANGED
@@ -22,7 +22,9 @@ import sys
|
|
22
22
|
|
23
23
|
"""
|
24
24
|
|
25
|
-
|
25
|
+
dir_path = os.path.expanduser("~")
|
26
|
+
config_file = os.path.join(dir_path, 'spd.txt')
|
27
|
+
content = config.read_config(file_path=config_file)
|
26
28
|
username, password, host, port = content['username'], content['password'], content['host'], content['port']
|
27
29
|
m_engine = mysql.MysqlUpload(username=username, password=password, host=host, port=port, charset='utf8mb4')
|
28
30
|
|
@@ -468,7 +470,7 @@ class MysqlDatasQuery:
|
|
468
470
|
'店铺名称': 1,
|
469
471
|
}
|
470
472
|
__res = []
|
471
|
-
for year in range(
|
473
|
+
for year in range(2025, datetime.datetime.today().year+1):
|
472
474
|
df = self.download.data_to_df(
|
473
475
|
db_name='推广数据_圣积天猫店',
|
474
476
|
table_name=f'主体报表_{year}',
|
@@ -2459,6 +2461,7 @@ class MysqlDatasQuery:
|
|
2459
2461
|
df_tm_living = pd.DataFrame() # 天猫超级直播
|
2460
2462
|
df_jd = pd.DataFrame() # 京东推广
|
2461
2463
|
df_jd_qzyx = pd.DataFrame() # 京东全站推广
|
2464
|
+
df_jd_ziying = pd.DataFrame() # 京东推广
|
2462
2465
|
|
2463
2466
|
start_date, end_date = self.months_data(num=self.months)
|
2464
2467
|
projection = {
|
@@ -2525,7 +2528,7 @@ class MysqlDatasQuery:
|
|
2525
2528
|
)
|
2526
2529
|
# sj圣积
|
2527
2530
|
__res = []
|
2528
|
-
for year in range(
|
2531
|
+
for year in range(2025, datetime.datetime.today().year + 1):
|
2529
2532
|
df_sj = self.download.data_to_df(
|
2530
2533
|
db_name='推广数据_圣积天猫店',
|
2531
2534
|
table_name=f'营销场景报表_{year}',
|
@@ -2783,7 +2786,52 @@ class MysqlDatasQuery:
|
|
2783
2786
|
df_jd_qzyx = df_jd_qzyx[['日期', '店铺名称', '营销场景', '花费', '展现量', '点击量', '成交笔数', '成交金额']]
|
2784
2787
|
df_jd_qzyx = df_jd_qzyx[df_jd_qzyx['花费'] > 0]
|
2785
2788
|
|
2786
|
-
|
2789
|
+
projection = {
|
2790
|
+
'日期': 1,
|
2791
|
+
'产品线': 1,
|
2792
|
+
'触发sku_id': 1,
|
2793
|
+
'跟单sku_id': 1,
|
2794
|
+
'花费': 1,
|
2795
|
+
'展现数': 1,
|
2796
|
+
'点击数': 1,
|
2797
|
+
'直接订单行': 1,
|
2798
|
+
'直接订单金额': 1,
|
2799
|
+
'总订单行': 1,
|
2800
|
+
'总订单金额': 1,
|
2801
|
+
'直接加购数': 1,
|
2802
|
+
'总加购数': 1,
|
2803
|
+
'spu_id': 1,
|
2804
|
+
'店铺名称': 1,
|
2805
|
+
}
|
2806
|
+
__res = []
|
2807
|
+
for year in range(2025, datetime.datetime.today().year + 1):
|
2808
|
+
df_jd_ziying = self.download.data_to_df(
|
2809
|
+
db_name='京东数据3',
|
2810
|
+
table_name=f'推广数据_京准通_自营店_{year}',
|
2811
|
+
start_date=start_date,
|
2812
|
+
end_date=end_date,
|
2813
|
+
projection=projection,
|
2814
|
+
)
|
2815
|
+
__res.append(df_jd_ziying)
|
2816
|
+
df_jd_ziying = pd.concat(__res, ignore_index=True)
|
2817
|
+
if len(df_jd_ziying) > 0:
|
2818
|
+
df_jd_ziying = df_jd_ziying.groupby(
|
2819
|
+
['日期', '店铺名称', '产品线', '触发sku_id', '跟单sku_id', 'spu_id', '花费', '展现数', '点击数'],
|
2820
|
+
as_index=False).agg(
|
2821
|
+
**{
|
2822
|
+
'直接订单行': ('直接订单行', np.max),
|
2823
|
+
'直接订单金额': ('直接订单金额', np.max),
|
2824
|
+
'成交笔数': ('总订单行', np.max),
|
2825
|
+
'成交金额': ('总订单金额', np.max),
|
2826
|
+
'直接加购数': ('直接加购数', np.max),
|
2827
|
+
'加购量': ('总加购数', np.max),
|
2828
|
+
}
|
2829
|
+
)
|
2830
|
+
df_jd_ziying = df_jd_ziying[['日期', '店铺名称', '产品线', '花费', '展现数', '点击数', '加购量', '成交笔数', '成交金额']]
|
2831
|
+
df_jd_ziying.rename(columns={'产品线': '营销场景', '展现数': '展现量', '点击数': '点击量'}, inplace=True)
|
2832
|
+
df_jd_ziying = df_jd_ziying[df_jd_ziying['花费'] > 0]
|
2833
|
+
|
2834
|
+
_datas = [item for item in [df_tm, df_tb, df_tb_qzt, df_al, df_sj, df_tm_pxb, df_tm_living, df_jd, df_jd_qzyx, df_jd_ziying] if len(item) > 0] # 阻止空的 dataframe
|
2787
2835
|
df = pd.concat(_datas, axis=0, ignore_index=True)
|
2788
2836
|
# 超级直播全站推广不包含在营销场景报表中,所以单独添加 2025-03-05
|
2789
2837
|
projection = {
|
mdbq/log/spider_logging.py
CHANGED
@@ -10,12 +10,11 @@ def setup_logging(reMoveOldHandler=True):
|
|
10
10
|
"""
|
11
11
|
reMoveOldHandler: 替换根日志记录器的所有现有处理器
|
12
12
|
"""
|
13
|
-
|
13
|
+
dir_path = os.path.expanduser("~")
|
14
|
+
if not os.path.isdir(os.path.join(dir_path, 'logfile')):
|
15
|
+
os.makedirs(os.path.join(dir_path, 'logfile'))
|
14
16
|
|
15
|
-
|
16
|
-
os.makedirs(os.path.join(D_PATH, 'logfile'))
|
17
|
-
|
18
|
-
log_file = os.path.join(D_PATH, 'logfile', 'spider_tg.log')
|
17
|
+
log_file = os.path.join(dir_path, 'logfile', 'spider_tg.log')
|
19
18
|
file_handler = RotatingFileHandler(
|
20
19
|
filename=log_file,
|
21
20
|
maxBytes=3*1024*1024, # 3MB
|
@@ -47,7 +47,9 @@ upload_path = os.path.join(D_PATH, '数据上传中心') # 此目录位于下
|
|
47
47
|
if not os.path.exists(upload_path): # 数据中心根目录
|
48
48
|
os.makedirs(upload_path)
|
49
49
|
|
50
|
-
|
50
|
+
dir_path = os.path.expanduser("~")
|
51
|
+
config_file = os.path.join(dir_path, 'spd.txt')
|
52
|
+
content = config.read_config(file_path=config_file)
|
51
53
|
username, password, host, port = content['username'], content['password'], content['host'], content['port']
|
52
54
|
m_engine = mysql.MysqlUpload(username=username, password=password, host=host, port=port, charset='utf8mb4')
|
53
55
|
|
mdbq/redis/getredis.py
CHANGED
@@ -17,7 +17,8 @@ import orjson
|
|
17
17
|
logger = logging.getLogger(__name__)
|
18
18
|
|
19
19
|
# 创建一个文件处理器,用于将日志写入文件
|
20
|
-
dir_path = os.path.
|
20
|
+
dir_path = os.path.expanduser("~")
|
21
|
+
# config_file = os.path.join(dir_path, 'spd.txt')
|
21
22
|
log_file = os.path.join(dir_path, 'logfile', 'redis.log')
|
22
23
|
if not os.path.isdir(os.path.join(dir_path, 'logfile')):
|
23
24
|
os.mkdir(os.path.join(dir_path, 'logfile'))
|
mdbq/spider/aikucun.py
CHANGED
@@ -22,8 +22,9 @@ from mdbq.mysql import s_query
|
|
22
22
|
from mdbq.config import config
|
23
23
|
from mdbq.other import ua_sj
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
dir_path = os.path.expanduser("~")
|
26
|
+
config_file = os.path.join(dir_path, 'spd.txt')
|
27
|
+
content = config.read_config(file_path=config_file)
|
27
28
|
username, password, host, port = content['username'], content['password'], content['host'], content['port']
|
28
29
|
|
29
30
|
m_engine = mysql.MysqlUpload(username=username, password=password, host=host, port=port, charset='utf8mb4')
|
@@ -1,8 +1,7 @@
|
|
1
1
|
mdbq/__init__.py,sha256=Il5Q9ATdX8yXqVxtP_nYqUhExzxPC_qk_WXQ_4h0exg,16
|
2
|
-
mdbq/__version__.py,sha256=
|
2
|
+
mdbq/__version__.py,sha256=N2YV132Ke9nxG8e_N4DlVVVafsd63H4Sbusd36SCowU,17
|
3
3
|
mdbq/aggregation/__init__.py,sha256=EeDqX2Aml6SPx8363J-v1lz0EcZtgwIBYyCJV6CcEDU,40
|
4
|
-
mdbq/aggregation/
|
5
|
-
mdbq/aggregation/query_data.py,sha256=R8KL_tX6kU3Na2Gy-FGzNaGRZEzCl8bptYgOTSXYDpw,178194
|
4
|
+
mdbq/aggregation/query_data.py,sha256=fbNyjRlJF3ycVBfAmj_JXMaauUmj3oIFIzKx2XV2sR4,180368
|
6
5
|
mdbq/bdup/__init__.py,sha256=AkhsGk81SkG1c8FqDH5tRq-8MZmFobVbN60DTyukYTY,28
|
7
6
|
mdbq/bdup/bdup.py,sha256=hJs815hGFwm_X5bP2i9XugG2w2ZY_F0n3-Q0hVpIPPw,4892
|
8
7
|
mdbq/config/__init__.py,sha256=jso1oHcy6cJEfa7udS_9uO5X6kZLoPBF8l3wCYmr5dM,18
|
@@ -12,26 +11,25 @@ mdbq/dataframe/__init__.py,sha256=2HtCN8AdRj53teXDqzysC1h8aPL-mMFy561ESmhehGQ,22
|
|
12
11
|
mdbq/dataframe/converter.py,sha256=lETYhT7KXlWzWwqguqhk6vI6kj4rnOBEW1lhqKy2Abc,5035
|
13
12
|
mdbq/log/__init__.py,sha256=Mpbrav0s0ifLL7lVDAuePEi1hJKiSHhxcv1byBKDl5E,15
|
14
13
|
mdbq/log/mylogger.py,sha256=oaT7Bp-Hb9jZt52seP3ISUuxVcI19s4UiqTeouScBO0,3258
|
15
|
-
mdbq/log/spider_logging.py,sha256=
|
14
|
+
mdbq/log/spider_logging.py,sha256=KX9TTUn9naZNBACCEFhyTktnWhr5JaSNQLppLGyrm9Y,1645
|
16
15
|
mdbq/mongo/__init__.py,sha256=SILt7xMtQIQl_m-ik9WLtJSXIVf424iYgCfE_tnQFbw,13
|
17
16
|
mdbq/mysql/__init__.py,sha256=A_DPJyAoEvTSFojiI2e94zP0FKtCkkwKP1kYUCSyQzo,11
|
18
17
|
mdbq/mysql/mysql.py,sha256=tR6l4Zzn9j6zKaFcy0Ktw2oL8OoX3QB6jDoDp1l2fiM,95474
|
19
18
|
mdbq/mysql/s_query.py,sha256=09Dp7DrVXui6dAI6zFDfrsUOdjPblF_oYUpgqbZMhXg,8757
|
20
19
|
mdbq/mysql/year_month_day.py,sha256=VgewoE2pJxK7ErjfviL_SMTN77ki8GVbTUcao3vFUCE,1523
|
21
20
|
mdbq/other/__init__.py,sha256=jso1oHcy6cJEfa7udS_9uO5X6kZLoPBF8l3wCYmr5dM,18
|
22
|
-
mdbq/other/download_sku_picture.py,sha256=
|
21
|
+
mdbq/other/download_sku_picture.py,sha256=YU8DxKMXbdeE1OOKEA848WVp62jYHw5O4tXTjUdq9H0,44832
|
23
22
|
mdbq/other/porxy.py,sha256=UHfgEyXugogvXgsG68a7QouUCKaohTKKkI4RN-kYSdQ,4961
|
24
23
|
mdbq/other/pov_city.py,sha256=AEOmCOzOwyjHi9LLZWPKi6DUuSC-_M163664I52u9qw,21050
|
25
24
|
mdbq/other/ua_sj.py,sha256=JuVYzc_5QZ9s_oQSrTHVKkQv4S_7-CWx4oIKOARn_9U,22178
|
26
25
|
mdbq/pbix/__init__.py,sha256=Trtfaynu9RjoTyLLYBN2xdRxTvm_zhCniUkVTAYwcjo,24
|
27
26
|
mdbq/pbix/pbix_refresh.py,sha256=JUjKW3bNEyoMVfVfo77UhguvS5AWkixvVhDbw4_MHco,2396
|
28
27
|
mdbq/pbix/refresh_all.py,sha256=OBT9EewSZ0aRS9vL_FflVn74d4l2G00wzHiikCC4TC0,5926
|
29
|
-
mdbq/pbix/refresh_all_old.py,sha256=_pq3WSQ728GPtEG5pfsZI2uTJhU8D6ra-htIk1JXYzw,7192
|
30
28
|
mdbq/redis/__init__.py,sha256=YtgBlVSMDphtpwYX248wGge1x-Ex_mMufz4-8W0XRmA,12
|
31
|
-
mdbq/redis/getredis.py,sha256=
|
29
|
+
mdbq/redis/getredis.py,sha256=Uk8-cOWT0JU1qRyIVqdbYokSLvkDIAfcokmYj1ebw8k,24104
|
32
30
|
mdbq/spider/__init__.py,sha256=RBMFXGy_jd1HXZhngB2T2XTvJqki8P_Fr-pBcwijnew,18
|
33
|
-
mdbq/spider/aikucun.py,sha256=
|
34
|
-
mdbq-3.8.
|
35
|
-
mdbq-3.8.
|
36
|
-
mdbq-3.8.
|
37
|
-
mdbq-3.8.
|
31
|
+
mdbq/spider/aikucun.py,sha256=cYtLIEvvfKZ0pUeASpKaMY31vOKFa74KNcZQ3iCiL0c,19724
|
32
|
+
mdbq-3.8.4.dist-info/METADATA,sha256=DKnJoT-wW88fh5-SnfD6v748tCpgii5KB7gqqe2fdAU,363
|
33
|
+
mdbq-3.8.4.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
|
34
|
+
mdbq-3.8.4.dist-info/top_level.txt,sha256=2FQ-uLnCSB-OwFiWntzmwosW3X2Xqsg0ewh1axsaylA,5
|
35
|
+
mdbq-3.8.4.dist-info/RECORD,,
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# -*- coding: UTF-8 –*-
|
2
|
-
from mdbq.mysql import mysql
|
3
|
-
from mdbq.config import default
|
4
|
-
import subprocess
|
5
|
-
import psutil
|
6
|
-
import time
|
7
|
-
import platform
|
8
|
-
import logging
|
9
|
-
"""
|
10
|
-
对指定数据库所有冗余数据进行清理
|
11
|
-
"""
|
12
|
-
targe_host, hostname, local = default.return_default_host()
|
13
|
-
m_engine, username, password, host, port = default.get_mysql_engine(platform='Windows', hostname=hostname, sql='mysql', local=local, config_file=None)
|
14
|
-
if not username:
|
15
|
-
logger.info(f'找不到主机:')
|
16
|
-
|
17
|
-
logger = logging.getLogger(__name__)
|
18
|
-
|
19
|
-
|
20
|
-
def op_data(db_name_lists, days: int = 63, is_mongo=True, is_mysql=True):
|
21
|
-
# Mysql
|
22
|
-
if is_mysql:
|
23
|
-
s = mysql.OptimizeDatas(username=username, password=password, host=host, port=port)
|
24
|
-
s.db_name_lists = db_name_lists
|
25
|
-
s.days = days
|
26
|
-
s.optimize_list()
|
27
|
-
|
28
|
-
|
29
|
-
if __name__ == '__main__':
|
30
|
-
op_data(db_name_lists=['聚合数据'], days=10, is_mongo=True, is_mysql=True)
|
mdbq/pbix/refresh_all_old.py
DELETED
@@ -1,177 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
import sys
|
3
|
-
import win32com.client
|
4
|
-
import time
|
5
|
-
import multiprocessing
|
6
|
-
import psutil
|
7
|
-
from pywinauto.application import Application
|
8
|
-
import warnings
|
9
|
-
from mdbq.config import set_support
|
10
|
-
|
11
|
-
warnings.filterwarnings('ignore')
|
12
|
-
top_path = os.path.realpath(os.path.dirname(sys.argv[0])) # 程序运行目录, 打包时使用
|
13
|
-
sys.path.append(top_path)
|
14
|
-
|
15
|
-
|
16
|
-
class RefreshAll:
|
17
|
-
def __init__(self):
|
18
|
-
self.my_conf = os.path.join(set_support.SetSupport(dirname='support').dirname, '.my_conf')
|
19
|
-
self.pbix_path = os.path.join(set_support.SetSupport(dirname='support').dirname, 'ref_list.txt')
|
20
|
-
self.excel_path = os.path.join(set_support.SetSupport(dirname='support').dirname, 'ref_list.txt')
|
21
|
-
self.run_py_path = 'run_py'
|
22
|
-
self.procname = 'PBIDesktop.exe'
|
23
|
-
|
24
|
-
def refresh_pbix(self):
|
25
|
-
# 刷新 PBI
|
26
|
-
if not os.path.exists(self.pbix_path):
|
27
|
-
print(f'{self.pbix_path}: PBIxx file not found. ')
|
28
|
-
return
|
29
|
-
with open(self.pbix_path, 'r', encoding='utf-8') as f:
|
30
|
-
content = f.readlines()
|
31
|
-
content = [item.strip() for item in content if not item.strip().startswith('#') and not item.strip().startswith('[')]
|
32
|
-
pbix_list = [item for item in content if item]
|
33
|
-
|
34
|
-
if not pbix_list:
|
35
|
-
return
|
36
|
-
for filename in pbix_list:
|
37
|
-
if filename.endswith('.pbix'):
|
38
|
-
newfile = os.path.join(self.run_py_path, filename)
|
39
|
-
"""刷新程序"""
|
40
|
-
for es in range(4):
|
41
|
-
try:
|
42
|
-
print(f'正在刷新 >>>{filename}')
|
43
|
-
self.pbi(path=newfile)
|
44
|
-
print('文件刷新 >>>' + filename)
|
45
|
-
break
|
46
|
-
except Exception as e:
|
47
|
-
print(e)
|
48
|
-
print('报错的文件 >>>' + filename + ' >> ' + str(es + 1))
|
49
|
-
|
50
|
-
def refresh_excel(self):
|
51
|
-
# 刷新 excel
|
52
|
-
if not os.path.exists(self.excel_path):
|
53
|
-
print(f'{self.excel_path}: Excel file not found. ')
|
54
|
-
return
|
55
|
-
with open(self.excel_path, 'r', encoding='utf-8') as f:
|
56
|
-
content = f.readlines()
|
57
|
-
content = [item.strip() for item in content if not item.strip().startswith('#')]
|
58
|
-
excel_list = [item for item in content if item]
|
59
|
-
|
60
|
-
if not excel_list:
|
61
|
-
return
|
62
|
-
for filename in excel_list:
|
63
|
-
if filename.endswith('.xlsx'):
|
64
|
-
try:
|
65
|
-
print(f'正在刷新 >>>{filename}')
|
66
|
-
path = os.path.join(top_path, self.run_py_path, filename) # 拼接文件路径
|
67
|
-
xlapp = win32com.client.Dispatch('Excel.Application') # 创建Excel程序App
|
68
|
-
xlapp.Visible = False # 窗口是否可见
|
69
|
-
xlapp.DisplayAlerts = False # 是否显示警告信息
|
70
|
-
wb = xlapp.Workbooks.Open(path)
|
71
|
-
conjuncts = wb.Connections.Count # 统计工作簿含有多少外部链接
|
72
|
-
if conjuncts == 0:
|
73
|
-
wb.Close(SaveChanges=False)
|
74
|
-
xlapp.Quit()
|
75
|
-
else:
|
76
|
-
time.sleep(2)
|
77
|
-
wb.RefreshAll()
|
78
|
-
xlapp.CalculateUntilAsyncQueriesDone()
|
79
|
-
time.sleep(2)
|
80
|
-
wb.Save()
|
81
|
-
wb.Close(SaveChanges=True)
|
82
|
-
xlapp.Quit()
|
83
|
-
print('文件刷新 >>>' + filename)
|
84
|
-
except Exception as e:
|
85
|
-
print(e)
|
86
|
-
|
87
|
-
def refresh_excel2(self, excel_file):
|
88
|
-
# 刷新 excel
|
89
|
-
if excel_file.endswith('.xlsx'):
|
90
|
-
try:
|
91
|
-
print(f'正在刷新 >>>{excel_file}')
|
92
|
-
xlapp = win32com.client.Dispatch('Excel.Application') # 创建Excel程序App
|
93
|
-
xlapp.Visible = False # 窗口是否可见
|
94
|
-
xlapp.DisplayAlerts = False # 是否显示警告信息
|
95
|
-
wb = xlapp.Workbooks.Open(excel_file)
|
96
|
-
conjuncts = wb.Connections.Count # 统计工作簿含有多少外部链接
|
97
|
-
if conjuncts == 0:
|
98
|
-
wb.Close(SaveChanges=False)
|
99
|
-
xlapp.Quit()
|
100
|
-
else:
|
101
|
-
time.sleep(2)
|
102
|
-
wb.RefreshAll()
|
103
|
-
xlapp.CalculateUntilAsyncQueriesDone()
|
104
|
-
time.sleep(2)
|
105
|
-
wb.Save()
|
106
|
-
wb.Close(SaveChanges=True)
|
107
|
-
xlapp.Quit()
|
108
|
-
print('文件刷新 >>>' + excel_file)
|
109
|
-
except Exception as e:
|
110
|
-
print(e)
|
111
|
-
|
112
|
-
def pbi(self, path, _timeout=300):
|
113
|
-
"""
|
114
|
-
这是原本属于独立的库模块: pbix_refresh
|
115
|
-
path: pbi文件路径
|
116
|
-
_timeout: 刷新等待时间
|
117
|
-
如果连接失败,请将 power bi 文件名的特殊字符(空格等)去掉或改为英文文件名试试
|
118
|
-
"""
|
119
|
-
# 关闭已打开的 power bi进程
|
120
|
-
for proc in psutil.process_iter():
|
121
|
-
if proc.name() == self.procname:
|
122
|
-
proc.kill()
|
123
|
-
time.sleep(1)
|
124
|
-
|
125
|
-
# 启动 Power bi
|
126
|
-
os.system('start "" "' + path + '"')
|
127
|
-
time.sleep(5)
|
128
|
-
|
129
|
-
# 通过 connect 方法连接进程
|
130
|
-
app = Application(backend='uia').connect(path=self.procname)
|
131
|
-
# title_re可以通过正则表达式连接:".*Power BI Desktop", 仅限 2023年9月之前的 Power bi版本
|
132
|
-
# 2023年10月之后的版本没有此窗口后缀, 因此需用文件名找窗口
|
133
|
-
# 如果同时打开了其他同名的文件(非 power bi文件时), 可能会引发错误
|
134
|
-
_filename = os.path.splitext(os.path.basename(path))[0] # 文件名不含后缀
|
135
|
-
win = app.window(title_re=f'{_filename}.*?') # 连接 pbi 窗口
|
136
|
-
time.sleep(10)
|
137
|
-
# win.print_control_identifiers() # 打印窗口全部信息, 推荐使用 inspect 开发工具查询窗口句柄信息
|
138
|
-
num = 0
|
139
|
-
while True:
|
140
|
-
try:
|
141
|
-
win['刷新'].wait("enabled", timeout=_timeout)
|
142
|
-
time.sleep(3)
|
143
|
-
win['刷新'].click()
|
144
|
-
break
|
145
|
-
except:
|
146
|
-
print(f'{path}, 未识别窗口句柄, 连接超时')
|
147
|
-
num += 1
|
148
|
-
if num > 1:
|
149
|
-
break
|
150
|
-
|
151
|
-
num = 0
|
152
|
-
while True:
|
153
|
-
try:
|
154
|
-
win['保存'].wait("enabled", timeout=_timeout) # timeout 通过"保存"按键状态, 等待刷新窗口关闭, 时间不要设置太短
|
155
|
-
time.sleep(3)
|
156
|
-
win['保存'].click()
|
157
|
-
break
|
158
|
-
except:
|
159
|
-
print(f'{path}, 未识别窗口句柄, 文件未保存')
|
160
|
-
num += 1
|
161
|
-
if num > 1:
|
162
|
-
break
|
163
|
-
# win.type_keys("^s")
|
164
|
-
win.wait("enabled", timeout=15)
|
165
|
-
win.close()
|
166
|
-
|
167
|
-
# 关闭进程
|
168
|
-
for proc in psutil.process_iter():
|
169
|
-
if proc.name() == self.procname:
|
170
|
-
proc.kill()
|
171
|
-
|
172
|
-
|
173
|
-
if __name__ == '__main__':
|
174
|
-
# r = RefreshAll()
|
175
|
-
# # r.refresh_pbix()
|
176
|
-
# r.refresh_excel()
|
177
|
-
pass
|
File without changes
|
File without changes
|