mdbq 2.1.9__tar.gz → 2.2.1__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.
Files changed (48) hide show
  1. {mdbq-2.1.9 → mdbq-2.2.1}/PKG-INFO +1 -1
  2. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/aggregation/aggregation.py +1 -1
  3. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/company/copysh.py +6 -7
  4. mdbq-2.2.1/mdbq/pbix/refresh_all.py +152 -0
  5. mdbq-2.1.9/mdbq/pbix/refresh_all.py → mdbq-2.2.1/mdbq/pbix/refresh_all_old.py +3 -3
  6. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq.egg-info/PKG-INFO +1 -1
  7. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq.egg-info/SOURCES.txt +1 -0
  8. {mdbq-2.1.9 → mdbq-2.2.1}/setup.py +1 -1
  9. {mdbq-2.1.9 → mdbq-2.2.1}/README.txt +0 -0
  10. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/__init__.py +0 -0
  11. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/__version__.py +0 -0
  12. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/aggregation/__init__.py +0 -0
  13. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/aggregation/df_types.py +0 -0
  14. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/aggregation/mysql_types.py +0 -0
  15. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/aggregation/optimize_data.py +0 -0
  16. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/aggregation/query_data.py +0 -0
  17. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/bdup/__init__.py +0 -0
  18. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/bdup/bdup.py +0 -0
  19. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/clean/__init__.py +0 -0
  20. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/clean/data_clean.py +0 -0
  21. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/company/__init__.py +0 -0
  22. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/company/home_sh.py +0 -0
  23. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/config/__init__.py +0 -0
  24. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/config/get_myconf.py +0 -0
  25. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/config/products.py +0 -0
  26. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/config/set_support.py +0 -0
  27. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/config/update_conf.py +0 -0
  28. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/dataframe/__init__.py +0 -0
  29. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/dataframe/converter.py +0 -0
  30. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/log/__init__.py +0 -0
  31. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/log/mylogger.py +0 -0
  32. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/mongo/__init__.py +0 -0
  33. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/mongo/mongo.py +0 -0
  34. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/mysql/__init__.py +0 -0
  35. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/mysql/mysql.py +0 -0
  36. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/mysql/s_query.py +0 -0
  37. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/mysql/year_month_day.py +0 -0
  38. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/other/__init__.py +0 -0
  39. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/other/porxy.py +0 -0
  40. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/other/pov_city.py +0 -0
  41. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/other/sku_picture.py +0 -0
  42. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/other/ua_sj.py +0 -0
  43. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/pbix/__init__.py +0 -0
  44. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/pbix/pbix_refresh.py +0 -0
  45. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq/spider/__init__.py +0 -0
  46. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq.egg-info/dependency_links.txt +0 -0
  47. {mdbq-2.1.9 → mdbq-2.2.1}/mdbq.egg-info/top_level.txt +0 -0
  48. {mdbq-2.1.9 → mdbq-2.2.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mdbq
3
- Version: 2.1.9
3
+ Version: 2.2.1
4
4
  Home-page: https://pypi.org/project/mdbsql
5
5
  Author: xigua,
6
6
  Author-email: 2587125111@qq.com
@@ -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
  '单元报表',
@@ -255,19 +255,18 @@ class TbFiles:
255
255
  # 刷新共享位置的指定文件/文件夹
256
256
  excel_path = os.path.join(self.share_path, 'EXCEL报表')
257
257
  files = os.listdir(excel_path)
258
+ files = [f'{excel_path}\\{item}' for item in files if item.endswith('.xlsx') or item.endswith('.xls')]
258
259
  r = refresh_all.RefreshAll()
259
260
  for file in files:
260
- if '~' in file or 'DS_Store' in file or 'baidu' in file or 'xunlei' in name:
261
+ if '~' in file or 'DS_Store' in file or 'baidu' in file or 'xunlei' in file:
261
262
  continue
262
- if file.endswith('.xlsx'):
263
- # now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
264
- # print(f'{now}正在刷新 excel: {file}')
265
- r.refresh_excel2(excel_file=os.path.join(excel_path, file))
266
- time.sleep(10)
263
+ if file.endswith('.xlsx') or file.endswith('.xls'):
264
+ r.refresh_excel(file=file)
265
+ time.sleep(5)
267
266
 
268
267
  # 临时加的
269
268
  excel_file = f'\\\\192.168.1.198\\时尚事业部\\01.运营部\\0-电商周报-每周五更新\\WLM 周报-模版V1.xlsx'
270
- r.refresh_excel2(excel_file=excel_file)
269
+ r.refresh_excel(file=excel_file)
271
270
 
272
271
  self.before_max_time = self.check_change() # 重置值, 避免重复同步
273
272
 
@@ -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
@@ -171,7 +171,7 @@ class RefreshAll:
171
171
 
172
172
 
173
173
  if __name__ == '__main__':
174
- r = RefreshAll()
175
- # r.refresh_pbix()
176
- r.refresh_excel()
174
+ # r = RefreshAll()
175
+ # # r.refresh_pbix()
176
+ # r.refresh_excel()
177
177
  pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mdbq
3
- Version: 2.1.9
3
+ Version: 2.2.1
4
4
  Home-page: https://pypi.org/project/mdbsql
5
5
  Author: xigua,
6
6
  Author-email: 2587125111@qq.com
@@ -42,4 +42,5 @@ mdbq/other/ua_sj.py
42
42
  mdbq/pbix/__init__.py
43
43
  mdbq/pbix/pbix_refresh.py
44
44
  mdbq/pbix/refresh_all.py
45
+ mdbq/pbix/refresh_all_old.py
45
46
  mdbq/spider/__init__.py
@@ -3,7 +3,7 @@
3
3
  from setuptools import setup, find_packages
4
4
 
5
5
  setup(name='mdbq',
6
- version='2.1.9',
6
+ version='2.2.1',
7
7
  author='xigua, ',
8
8
  author_email="2587125111@qq.com",
9
9
  url='https://pypi.org/project/mdbsql',
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