-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from ts7ming/dev
功能合并
- Loading branch information
Showing
10 changed files
with
221 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import pandas as pd | ||
|
||
|
||
class Image: | ||
@staticmethod | ||
def df2image(df, file_path=None, col_width=None, font_size=None): | ||
""" | ||
基于 pandas.DataFrame 生成png图片 | ||
:param font_size: 字体大小 | ||
:param col_width: 列宽: auto: 根据传入 df 自动设置 也可以传入列表指定每列宽度 由plt自动设置, | ||
:param df: pd.DataFrame对象 | ||
:param file_path: 目标图片路径, 如果为None则自动生成临时路径 | ||
:return: | ||
""" | ||
import matplotlib.pylab as plt | ||
import tempfile | ||
|
||
if file_path is None: | ||
file_path = tempfile.gettempdir() + '/tmp.png' | ||
pd.set_option('display.unicode.ambiguous_as_wide', True) | ||
pd.set_option('display.unicode.east_asian_width', True) | ||
|
||
plt.figure() | ||
plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签 | ||
plt.subplots_adjust(top=0.7, bottom=0, left=0, right=1, hspace=3, wspace=3) | ||
plt.margins(1, 1) | ||
ax = plt.subplot(111, 1, 1) | ||
ax.xaxis.set_visible(False) | ||
ax.yaxis.set_visible(False) | ||
|
||
if col_width == 'auto': | ||
tmp_list = [max(len(str(a)), len(str(b))) for a, b in | ||
zip(list(df.head(1).to_records()[0])[1:], list(df.columns))] | ||
new_col_width = [x / sum(tmp_list) for x in tmp_list] | ||
dtable = ax.table(cellText=df.values, colLabels=df.columns, colWidths=new_col_width) | ||
elif col_width != 'auto' and col_width is not None: | ||
dtable = ax.table(cellText=df.values, colLabels=df.columns, colWidths=col_width) | ||
else: | ||
dtable = ax.table(cellText=df.values, colLabels=df.columns) | ||
if font_size is not None: | ||
dtable.auto_set_font_size(False) | ||
dtable.set_fontsize(font_size) | ||
plt.savefig(file_path, dpi=600, bbox_inches='tight') | ||
return file_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import sys | ||
from pyqueen.utility.utils import Utils | ||
|
||
doc = ''' | ||
____ ___ | ||
| _ \ _ _ / _ \ _ _ ___ ___ _ __ | ||
| |_) | | | | | | | | | |/ _ \/ _ \ '_ \ | ||
| __/| |_| | |_| | |_| | __/ __/ | | | | ||
|_| \__, |\__\_\\\__,_|\___|\___|_| |_| | ||
|___/ | ||
================================================================================= | ||
用法: pyqueen command args1,args2,... | ||
--- | ||
command: | ||
#1 sql2table [file_path] 从sql解析用到的表(通过正则解析, 有误差) (不带参数时读取剪切板) | ||
#2 getcode file_path 检测文件编码 | ||
#3 md5 基于剪切板文本生成md5 | ||
''' | ||
|
||
|
||
def cmd(): | ||
parms = sys.argv[1:] | ||
if len(parms) == 0: | ||
print(doc) | ||
elif parms[0] == 'sql2table': | ||
if len(parms) == 1: | ||
print('从剪切板读取SQL文本') | ||
import pyperclip | ||
sql_text = str(pyperclip.paste()).replace('\n', '').strip(' ') | ||
else: | ||
with open(parms[1], 'r', encoding='utf-8') as f: | ||
sql_text = f.read() | ||
tb_list = Utils.sql2table(sql_text) | ||
print('================= begin =========================\n') | ||
for tb in tb_list: | ||
print(tb) | ||
print('\n================= end =========================\n') | ||
elif parms[0] == 'getcode': | ||
if len(parms) >= 2: | ||
print('================= begin =========================\n') | ||
encoding, confidence = Utils.detect_encoding(parms[1]) | ||
print('文件编码: %s, 可信度: %s' % (str(encoding), str(confidence))) | ||
print('\n================= end =========================\n') | ||
else: | ||
print('指定文件路径') | ||
elif parms[0] == 'md5': | ||
import pyperclip | ||
text = str(pyperclip.paste()).replace('\n', '').strip(' ') | ||
print('================= begin =========================\n') | ||
print(Utils.md5(text)) | ||
print('\n================= end =========================\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters