Functions-d 1.38__tar.gz → 1.40__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.
- {functions_d-1.38 → functions_d-1.40}/Functions_d/Functions_d.py +15 -17
- {functions_d-1.38 → functions_d-1.40}/Functions_d.egg-info/PKG-INFO +1 -1
- {functions_d-1.38 → functions_d-1.40}/PKG-INFO +1 -1
- {functions_d-1.38 → functions_d-1.40}/setup.cfg +1 -1
- {functions_d-1.38 → functions_d-1.40}/Functions_d/__init__.py +0 -0
- {functions_d-1.38 → functions_d-1.40}/Functions_d.egg-info/SOURCES.txt +0 -0
- {functions_d-1.38 → functions_d-1.40}/Functions_d.egg-info/dependency_links.txt +0 -0
- {functions_d-1.38 → functions_d-1.40}/Functions_d.egg-info/requires.txt +0 -0
- {functions_d-1.38 → functions_d-1.40}/Functions_d.egg-info/top_level.txt +0 -0
- {functions_d-1.38 → functions_d-1.40}/README.md +0 -0
- {functions_d-1.38 → functions_d-1.40}/pyproject.toml +0 -0
- {functions_d-1.38 → functions_d-1.40}/setup.py +0 -0
|
@@ -7,7 +7,7 @@ import shutil
|
|
|
7
7
|
import time
|
|
8
8
|
import urllib.request
|
|
9
9
|
import WeComMsg
|
|
10
|
-
import xlwings as xw
|
|
10
|
+
# import xlwings as xw
|
|
11
11
|
import yagmail
|
|
12
12
|
import HiveClient
|
|
13
13
|
from PIL import ImageGrab, Image
|
|
@@ -20,7 +20,7 @@ from selenium.webdriver.edge.service import Service
|
|
|
20
20
|
from selenium.webdriver.edge.options import Options
|
|
21
21
|
from webdriver_manager.microsoft import EdgeChromiumDriverManager
|
|
22
22
|
import psutil
|
|
23
|
-
import pythoncom
|
|
23
|
+
# import pythoncom
|
|
24
24
|
from tenacity import retry, stop_after_attempt, wait_fixed
|
|
25
25
|
import requests
|
|
26
26
|
import pandas as pd
|
|
@@ -676,10 +676,10 @@ class DataProcessingAndMessaging:
|
|
|
676
676
|
|
|
677
677
|
# -------------------------- 写入Excel数据 --------------------------
|
|
678
678
|
def writer_excel_data(self, path, filename, send_file, sheet_data, headers):
|
|
679
|
+
import xlwings as xw
|
|
679
680
|
self.logger.info('开始处理Excel表格')
|
|
680
681
|
print('开始处理Excel表格')
|
|
681
682
|
filename = path + filename
|
|
682
|
-
send_file = send_file
|
|
683
683
|
dfs = []
|
|
684
684
|
sheet_names = []
|
|
685
685
|
clear_ranges = []
|
|
@@ -755,6 +755,8 @@ class DataProcessingAndMessaging:
|
|
|
755
755
|
|
|
756
756
|
# -------------------------- Excel截图(安全版) --------------------------
|
|
757
757
|
def screen(self, filename, sheetname, screen_area, img_name):
|
|
758
|
+
import pythoncom
|
|
759
|
+
import xlwings as xw
|
|
758
760
|
self.logger.info('开始截图')
|
|
759
761
|
print('开始截图')
|
|
760
762
|
pythoncom.CoInitialize()
|
|
@@ -1912,20 +1914,14 @@ class DataProcessingAndMessaging:
|
|
|
1912
1914
|
# -------------------------- Hive数据导出Snappy压缩Parquet文件 --------------------------
|
|
1913
1915
|
def export_parquet(self, df, file_no_suffix, save_dir=None):
|
|
1914
1916
|
"""
|
|
1915
|
-
将Hive查询返回的DataFrame
|
|
1916
|
-
:param df: Hive读取的DataFrame
|
|
1917
|
-
:param file_no_suffix: 不带后缀的文件名,方法内部自动拼接 .parquet
|
|
1918
|
-
:param save_dir: 存储目录路径;不传则默认使用实例内置self.path
|
|
1917
|
+
将Hive查询返回的DataFrame,自动去重列名,输出优化参数Snappy Parquet
|
|
1919
1918
|
"""
|
|
1920
|
-
# 判定存储目录,为空则使用默认脚本路径self.path
|
|
1921
1919
|
target_dir = save_dir if save_dir is not None else self.path
|
|
1922
|
-
# 拼接完整文件路径
|
|
1923
1920
|
file_name = f"{file_no_suffix}.parquet"
|
|
1924
1921
|
save_path = os.path.join(target_dir, file_name)
|
|
1925
1922
|
self.logger.info(f"开始处理Parquet导出,目标路径:{save_path}")
|
|
1926
1923
|
print(f"开始处理Parquet导出,目标路径:{save_path}")
|
|
1927
1924
|
try:
|
|
1928
|
-
# 截取列名,去掉库表前缀,重复字段自动加后缀区分
|
|
1929
1925
|
old_columns = list(df.columns)
|
|
1930
1926
|
new_cols = []
|
|
1931
1927
|
name_count = {}
|
|
@@ -1939,22 +1935,24 @@ class DataProcessingAndMessaging:
|
|
|
1939
1935
|
final_name = short_name
|
|
1940
1936
|
new_cols.append(final_name)
|
|
1941
1937
|
df.columns = new_cols
|
|
1942
|
-
self.logger.info(f"
|
|
1938
|
+
self.logger.info(f"列名清洗完成,共{len(df.columns)}个字段")
|
|
1943
1939
|
print(f"列名清洗完成,共{len(df.columns)}个字段")
|
|
1944
1940
|
|
|
1945
|
-
#
|
|
1941
|
+
# 增加优化参数,大幅提升PowerBI读取性能
|
|
1946
1942
|
df.to_parquet(
|
|
1947
1943
|
save_path,
|
|
1948
1944
|
engine="pyarrow",
|
|
1949
|
-
compression="snappy"
|
|
1945
|
+
compression="snappy",
|
|
1946
|
+
row_group_size=100000,
|
|
1947
|
+
use_dictionary=True,
|
|
1948
|
+
data_page_size=1048576
|
|
1950
1949
|
)
|
|
1951
|
-
# 获取文件大小日志
|
|
1952
1950
|
file_size_kb = round(os.path.getsize(save_path) / 1024, 2)
|
|
1953
|
-
success_msg = f"Parquet
|
|
1951
|
+
success_msg = f"Parquet导出完成,文件大小:{file_size_kb} KB,数据行数:{len(df)}"
|
|
1954
1952
|
self.logger.info(success_msg)
|
|
1955
1953
|
print(success_msg)
|
|
1956
1954
|
except Exception as e:
|
|
1957
|
-
err_msg = f"导出
|
|
1955
|
+
err_msg = f"导出Parquet失败,路径:{save_path},报错:{str(e)}"
|
|
1958
1956
|
self.logger.error(err_msg, exc_info=True)
|
|
1959
1957
|
print(err_msg)
|
|
1960
1958
|
raise
|
|
@@ -1989,7 +1987,7 @@ class DataProcessingAndMessaging:
|
|
|
1989
1987
|
final_name = short_name
|
|
1990
1988
|
new_cols.append(final_name)
|
|
1991
1989
|
df.columns = new_cols
|
|
1992
|
-
self.logger.info(f"
|
|
1990
|
+
self.logger.info(f"列名清洗完成,共{len(df.columns)}个字段")
|
|
1993
1991
|
print(f"列名清洗完成,共{len(df.columns)}个字段")
|
|
1994
1992
|
|
|
1995
1993
|
# 导出csv,utf-8-sig解决中文乱码,不输出索引
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|