mdbq 2.1.8__tar.gz → 2.2.0__tar.gz
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-2.1.8 → mdbq-2.2.0}/PKG-INFO +1 -1
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/aggregation/aggregation.py +1 -1
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/aggregation/query_data.py +4 -1
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/company/copysh.py +8 -8
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/mysql/s_query.py +1 -0
- mdbq-2.2.0/mdbq/pbix/refresh_all.py +152 -0
- mdbq-2.1.8/mdbq/pbix/refresh_all.py → mdbq-2.2.0/mdbq/pbix/refresh_all_old.py +3 -3
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq.egg-info/PKG-INFO +1 -1
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq.egg-info/SOURCES.txt +1 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/setup.py +1 -1
- {mdbq-2.1.8 → mdbq-2.2.0}/README.txt +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/__init__.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/__version__.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/aggregation/__init__.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/aggregation/df_types.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/aggregation/mysql_types.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/aggregation/optimize_data.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/bdup/__init__.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/bdup/bdup.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/clean/__init__.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/clean/data_clean.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/company/__init__.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/company/home_sh.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/config/__init__.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/config/get_myconf.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/config/products.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/config/set_support.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/config/update_conf.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/dataframe/__init__.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/dataframe/converter.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/log/__init__.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/log/mylogger.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/mongo/__init__.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/mongo/mongo.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/mysql/__init__.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/mysql/mysql.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/mysql/year_month_day.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/other/__init__.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/other/porxy.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/other/pov_city.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/other/sku_picture.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/other/ua_sj.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/pbix/__init__.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/pbix/pbix_refresh.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq/spider/__init__.py +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq.egg-info/dependency_links.txt +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/mdbq.egg-info/top_level.txt +0 -0
- {mdbq-2.1.8 → mdbq-2.2.0}/setup.cfg +0 -0
@@ -88,7 +88,7 @@ class DatabaseUpdate:
|
|
88
88
|
df = pd.DataFrame() # 初始化 df
|
89
89
|
encoding = self.get_encoding(file_path=os.path.join(root, name)) # 用于处理 csv 文件
|
90
90
|
tg_names = [
|
91
|
-
'账户报表', # 旧版,后来改成 营销场景报表了,C 店还是旧版
|
91
|
+
# '账户报表', # 旧版,后来改成 营销场景报表了,C 店还是旧版
|
92
92
|
'营销场景报表',
|
93
93
|
'计划报表',
|
94
94
|
'单元报表',
|
@@ -557,11 +557,14 @@ class MysqlDatasQuery:
|
|
557
557
|
|
558
558
|
df_tb = self.download.data_to_df(
|
559
559
|
db_name='推广数据_淘宝店',
|
560
|
-
table_name='
|
560
|
+
table_name='营销场景报表',
|
561
561
|
start_date=start_date,
|
562
562
|
end_date=end_date,
|
563
563
|
projection=projection,
|
564
564
|
)
|
565
|
+
# print(df_tb)
|
566
|
+
# df_tm.to_csv('/Users/xigua/Downloads/test2.csv', index=False, header=True, encoding='utf-8_sig')
|
567
|
+
# df_tb.to_csv('/Users/xigua/Downloads/test.csv', index=False, header=True, encoding='utf-8_sig')
|
565
568
|
df_tb.rename(columns={'场景名字': '营销场景'}, inplace=True)
|
566
569
|
df_tb = df_tb.groupby(
|
567
570
|
['日期', '营销场景', '花费'],
|
@@ -257,14 +257,15 @@ class TbFiles:
|
|
257
257
|
files = os.listdir(excel_path)
|
258
258
|
r = refresh_all.RefreshAll()
|
259
259
|
for file in files:
|
260
|
-
if file
|
261
|
-
|
262
|
-
|
263
|
-
r.
|
264
|
-
time.sleep(
|
260
|
+
if '~' in file or 'DS_Store' in file or 'baidu' in file or 'xunlei' in name:
|
261
|
+
continue
|
262
|
+
if file.endswith('.xlsx') or file.endswith('.xls'):
|
263
|
+
r.refresh_excel(file=file)
|
264
|
+
time.sleep(5)
|
265
265
|
|
266
|
-
|
267
|
-
|
266
|
+
# 临时加的
|
267
|
+
excel_file = f'\\\\192.168.1.198\\时尚事业部\\01.运营部\\0-电商周报-每周五更新\\WLM 周报-模版V1.xlsx'
|
268
|
+
r.refresh_excel(file=excel_file)
|
268
269
|
|
269
270
|
self.before_max_time = self.check_change() # 重置值, 避免重复同步
|
270
271
|
|
@@ -403,4 +404,3 @@ if __name__ == '__main__':
|
|
403
404
|
main()
|
404
405
|
# # 聚合数据,并清理聚合数据
|
405
406
|
# query_data.data_aggregation(service_databases=[{'company': 'mysql'}], months=1)
|
406
|
-
|
@@ -79,6 +79,7 @@ class QueryDatas:
|
|
79
79
|
else: # 没有指定获取列,且数据表也没有日期列,则返回全部列的全部数据
|
80
80
|
all_col = ', '.join([f"`{item}`" for item in cols_exist if item != 'id'])
|
81
81
|
sql = f"SELECT %s FROM `%s`.`%s`" % (all_col, db_name, table_name)
|
82
|
+
# print(sql)
|
82
83
|
cursor.execute(sql)
|
83
84
|
rows = cursor.fetchall() # 获取查询结果
|
84
85
|
columns = [desc[0] for desc in cursor.description]
|
@@ -0,0 +1,152 @@
|
|
1
|
+
import os
|
2
|
+
import sys
|
3
|
+
import win32com.client
|
4
|
+
import time
|
5
|
+
import psutil
|
6
|
+
from pywinauto.application import Application
|
7
|
+
import warnings
|
8
|
+
# from mdbq.config import set_support
|
9
|
+
|
10
|
+
warnings.filterwarnings('ignore')
|
11
|
+
# top_path = os.path.realpath(os.path.dirname(sys.argv[0])) # 程序运行目录, 打包时使用
|
12
|
+
# sys.path.append(top_path)
|
13
|
+
|
14
|
+
|
15
|
+
class RefreshAll:
|
16
|
+
def __init__(self):
|
17
|
+
# self.my_conf = os.path.join(set_support.SetSupport(dirname='support').dirname, '.my_conf')
|
18
|
+
# self.file = None
|
19
|
+
self.procname = 'PBIDesktop.exe'
|
20
|
+
|
21
|
+
def refresh_pbix(self, file):
|
22
|
+
# 刷新 PBI
|
23
|
+
if not os.path.isfile(file):
|
24
|
+
print(f'{file} -> 文件不存在')
|
25
|
+
return
|
26
|
+
# with open(self.pbix_path, 'r', encoding='utf-8') as f:
|
27
|
+
# content = f.readlines()
|
28
|
+
# content = [item.strip() for item in content if not item.strip().startswith('#') and not item.strip().startswith('[')]
|
29
|
+
# pbix_list = [item for item in content if item]
|
30
|
+
|
31
|
+
# if not pbix_list:
|
32
|
+
# return
|
33
|
+
# for filename in pbix_list:
|
34
|
+
if not file.endswith('.pbix'):
|
35
|
+
return
|
36
|
+
|
37
|
+
"""刷新程序"""
|
38
|
+
for es in range(4):
|
39
|
+
try:
|
40
|
+
print(f'正在刷新 >>>{file}')
|
41
|
+
self.pbi(path=file)
|
42
|
+
print('文件已刷新!')
|
43
|
+
break
|
44
|
+
except Exception as e:
|
45
|
+
print(e)
|
46
|
+
print('报错的文件 >>>' + file + ' >> ' + str(es + 1))
|
47
|
+
|
48
|
+
def refresh_excel(self, file):
|
49
|
+
# 刷新 excel
|
50
|
+
if not os.path.isfile(file):
|
51
|
+
print(f'{file} -> 文件不存在')
|
52
|
+
return
|
53
|
+
if not file.endswith('.xlsx') and not file.endswith('.xls'):
|
54
|
+
return
|
55
|
+
|
56
|
+
# with open(self.excel_path, 'r', encoding='utf-8') as f:
|
57
|
+
# content = f.readlines()
|
58
|
+
# content = [item.strip() for item in content if not item.strip().startswith('#')]
|
59
|
+
# excel_list = [item for item in content if item]
|
60
|
+
#
|
61
|
+
# if not excel_list:
|
62
|
+
# return
|
63
|
+
try:
|
64
|
+
print(f'正在刷新 >>>{file}')
|
65
|
+
xlapp = win32com.client.Dispatch('Excel.Application') # 创建Excel程序App
|
66
|
+
xlapp.Visible = False # 窗口是否可见
|
67
|
+
xlapp.DisplayAlerts = False # 是否显示警告信息
|
68
|
+
wb = xlapp.Workbooks.Open(file)
|
69
|
+
conjuncts = wb.Connections.Count # 统计工作簿含有多少外部链接
|
70
|
+
if conjuncts == 0:
|
71
|
+
wb.Close(SaveChanges=False)
|
72
|
+
xlapp.Quit()
|
73
|
+
else:
|
74
|
+
time.sleep(2)
|
75
|
+
wb.RefreshAll()
|
76
|
+
xlapp.CalculateUntilAsyncQueriesDone()
|
77
|
+
time.sleep(2)
|
78
|
+
wb.Save()
|
79
|
+
wb.Close(SaveChanges=True)
|
80
|
+
xlapp.Quit()
|
81
|
+
print('文件已刷新!')
|
82
|
+
except Exception as e:
|
83
|
+
print(file, e)
|
84
|
+
|
85
|
+
|
86
|
+
def pbi(self, path, _timeout=300):
|
87
|
+
"""
|
88
|
+
会被 refresh_pbix 函数调用
|
89
|
+
这是原本属于独立的库模块: pbix_refresh
|
90
|
+
path: pbi文件路径
|
91
|
+
_timeout: 刷新等待时间
|
92
|
+
如果连接失败,请将 power bi 文件名的特殊字符(空格等)去掉或改为英文文件名试试
|
93
|
+
"""
|
94
|
+
# 关闭已打开的 power bi进程
|
95
|
+
for proc in psutil.process_iter():
|
96
|
+
if proc.name() == self.procname:
|
97
|
+
proc.kill()
|
98
|
+
time.sleep(1)
|
99
|
+
|
100
|
+
# 启动 Power bi
|
101
|
+
os.system('start "" "' + path + '"')
|
102
|
+
time.sleep(5)
|
103
|
+
|
104
|
+
# 通过 connect 方法连接进程
|
105
|
+
app = Application(backend='uia').connect(path=self.procname)
|
106
|
+
# title_re可以通过正则表达式连接:".*Power BI Desktop", 仅限 2023年9月之前的 Power bi版本
|
107
|
+
# 2023年10月之后的版本没有此窗口后缀, 因此需用文件名找窗口
|
108
|
+
# 如果同时打开了其他同名的文件(非 power bi文件时), 可能会引发错误
|
109
|
+
_filename = os.path.splitext(os.path.basename(path))[0] # 文件名不含后缀
|
110
|
+
win = app.window(title_re=f'{_filename}.*?') # 连接 pbi 窗口
|
111
|
+
time.sleep(10)
|
112
|
+
# win.print_control_identifiers() # 打印窗口全部信息, 推荐使用 inspect 开发工具查询窗口句柄信息
|
113
|
+
num = 0
|
114
|
+
while True:
|
115
|
+
try:
|
116
|
+
win['刷新'].wait("enabled", timeout=_timeout)
|
117
|
+
time.sleep(3)
|
118
|
+
win['刷新'].click()
|
119
|
+
break
|
120
|
+
except:
|
121
|
+
print(f'{path}, 未识别窗口句柄, 连接超时')
|
122
|
+
num += 1
|
123
|
+
if num > 1:
|
124
|
+
break
|
125
|
+
|
126
|
+
num = 0
|
127
|
+
while True:
|
128
|
+
try:
|
129
|
+
win['保存'].wait("enabled", timeout=_timeout) # timeout 通过"保存"按键状态, 等待刷新窗口关闭, 时间不要设置太短
|
130
|
+
time.sleep(3)
|
131
|
+
win['保存'].click()
|
132
|
+
break
|
133
|
+
except:
|
134
|
+
print(f'{path}, 未识别窗口句柄, 文件未保存')
|
135
|
+
num += 1
|
136
|
+
if num > 1:
|
137
|
+
break
|
138
|
+
# win.type_keys("^s")
|
139
|
+
win.wait("enabled", timeout=15)
|
140
|
+
win.close()
|
141
|
+
|
142
|
+
# 关闭进程
|
143
|
+
for proc in psutil.process_iter():
|
144
|
+
if proc.name() == self.procname:
|
145
|
+
proc.kill()
|
146
|
+
|
147
|
+
|
148
|
+
if __name__ == '__main__':
|
149
|
+
# r = RefreshAll()
|
150
|
+
# # r.refresh_pbix()
|
151
|
+
# r.refresh_excel()
|
152
|
+
pass
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|