diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..c68d9a8 Binary files /dev/null and b/favicon.ico differ diff --git a/main.ui b/main.ui index 94d160a..a761119 100644 --- a/main.ui +++ b/main.ui @@ -7,7 +7,7 @@ 0 0 600 - 830 + 850 @@ -19,21 +19,21 @@ 600 - 830 + 850 600 - 830 + 850 - 中国建材总院宣传工作信息化管理平台 + 中国建材总院信息统计平台 - start.icostart.ico + favicon.icofavicon.ico false @@ -64,7 +64,7 @@ 10 280 191 - 91 + 81 @@ -127,7 +127,7 @@ 10 - 540 + 510 581 121 @@ -323,9 +323,9 @@ - 150 + 390 0 - 291 + 211 31 @@ -341,7 +341,7 @@ color:white; - 中国建材总院宣传工作信息化管理平台 + 中国建材总院信息统计平台 Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -356,7 +356,7 @@ 220 280 371 - 251 + 231 @@ -373,7 +373,7 @@ 10 20 351 - 221 + 201 @@ -390,9 +390,9 @@ 10 - 380 + 370 191 - 151 + 141 @@ -507,9 +507,9 @@ 10 - 670 + 630 581 - 111 + 171 @@ -535,14 +535,14 @@ - 汇总结果Excel: + 分析汇总数据 10 - 80 + 90 91 16 @@ -553,7 +553,7 @@ - 汇总打分Excel: + 总院年度文章表 @@ -573,8 +573,8 @@ 110 - 55 - 381 + 60 + 391 21 @@ -591,8 +591,8 @@ 110 - 80 - 381 + 90 + 401 16 @@ -655,6 +655,130 @@ 汇总打分 + + + + 520 + 110 + 51 + 24 + + + + 打开 + + + + + + 10 + 120 + 91 + 16 + + + + + 10 + + + + 总院年度打分表 + + + + + + 110 + 120 + 401 + 16 + + + + + 9 + + + + + + + + + + 10 + 100 + 561 + 16 + + + + Qt::Horizontal + + + + + + 10 + 130 + 561 + 16 + + + + Qt::Horizontal + + + + + + 10 + 150 + 91 + 16 + + + + + 10 + + + + 单位月度统计表 + + + + + + 520 + 140 + 51 + 24 + + + + 打开 + + + + + + 110 + 150 + 401 + 16 + + + + + 9 + + + + + + diff --git a/mycode/main.py b/mycode/main.py index 924442d..c5342e3 100644 --- a/mycode/main.py +++ b/mycode/main.py @@ -5,6 +5,8 @@ from mycode.base import BASE_DIR import re from openpyxl import load_workbook from urllib.parse import urlparse +from datetime import datetime +import numpy as np wechat_dir = os.path.join(BASE_DIR, 'article') web_dir = os.path.join(BASE_DIR, 'web_dir') @@ -23,106 +25,290 @@ def trans_to_json(): with open('biao.json', 'w', encoding='utf-8') as f: f.write(json_str) -def make_simple_csv_from_db(): +def make_simple_csv_from_db(now: datetime): + # 只查找当前月份更新的公众号数据 + now_month_str = now.strftime('%Y-%m-%d 00:00:00') conn = sqlite3.connect(os.path.join(BASE_DIR, 'db_folder/test.db')) - query = "select id, g.nickname, a.title, a.content_url, datetime(a.p_date, 'unixepoch', 'localtime') as pub_date from articles a LEFT JOIN gzhs g on g.biz = a.biz" + query = f""" + SELECT + id, + g.nickname, + a.title, + a.content_url, + datetime( a.p_date, 'unixepoch', 'localtime' ) AS pub_date, + datetime( g.updated_at, 'unixepoch', 'localtime' ) AS g_updated_at + FROM + articles a + LEFT JOIN gzhs g ON g.biz = a.biz + WHERE + g_updated_at > '{now_month_str}' + """ df = pd.read_sql_query(query, conn) # 关闭数据库连接 conn.close() # 将数据写入CSV文件 df.to_csv(os.path.join(wechat_dir, 'articles.csv'), index=False) +def float_to_int(value): + try: + return int(value) + except: + return value def get_cbma_info_from_db_and_ana(year: str = '2023'): + # 全年统计数据 + zybiz = "MzIzMDU4Njg3MA==" + df_fx = pd.DataFrame({"单位": [ "中国建材总院", + "瑞泰科技", "国检集团", "中材高新", "哈玻院", "中国新材院", "秦皇岛院", "西安墙材院", "咸阳陶瓷院", "钟表所", "总院北分", "中岩科技", "水泥新材院", "中建材科创院", "科建苑", "办公室(董事会办公室)", "党委组织部/人力资源部", "财务部", "科技部", "投资部", "企业管理部、安全环保部", "党群部/宣传统战部", + "党风办/巡察办、纪委综合室", "监督执纪室", "审计办公室"], + "公众号Biz": [zybiz, "MzU0MzgwMzg1NA==", "MzI1MjYzNDQ3NA==", "MzA5MDkzNDA0NQ==", "Mzg2MDg0NjkwNw==", "MzI3MTY5NTExNA==", "MzI1MzY1Njg5MQ==", "MzIxOTQwNjE2MQ==", + "Mzg3OTI0NTYzMA==", "MzA3NTU5NjM2MA==", "", "Mzg2NDgyMDM3OA==","","MzA5NTQ5MjY4Nw==", "", "", "", "", "", "", "", "", "", "", "", ], + # "供总院稿数": [], "供总院专稿数": [], "供总院组稿数": [], "供总院阅读10000及以上数": [], "供总院阅读5000及以上数": [], "供总院阅读1000及以上数": [], + # "1月发布数": [], "1月最高点击文章": [], + # "2月发布数": [], "2月最高点击文章": [], + # "3月发布数": [], "3月最高点击文章": [], + # "4月发布数": [], "4月最高点击文章": [], + # "5月发布数": [], "5月最高点击文章": [], + # "6月发布数": [], "6月最高点击文章": [], + # "7月发布数": [], "7月最高点击文章": [], + # "8月发布数": [], "8月最高点击文章": [], + # "9月发布数": [], "9月最高点击文章": [], + # "10月发布数": [], "10月最高点击文章": [], + # "11月发布数": [], "11月最高点击文章": [], + # "12月发布数": [], "12月最高点击文章": [], + # "半年发布数": [], "半年最高点击文章": [], + # "全年发布数": [], "全年最高点击文章": [] + }) + # 查询所有指定公众号的文章并按年/月排序 conn = sqlite3.connect(os.path.join(BASE_DIR, 'db_folder/test.db')) - query = f''' + query_gzhs = f''' SELECT id, - strftime('%Y年%m月%d日', datetime(a.p_date, 'unixepoch', 'localtime')) as pub_date, + g.biz as gbiz, + strftime('%Y', datetime(a.p_date, 'unixepoch', 'localtime')) as pub_year, + strftime('%m', datetime(a.p_date, 'unixepoch', 'localtime')) as pub_month, + strftime('%d', datetime(a.p_date, 'unixepoch', 'localtime')) as pub_day, g.nickname, a.title, a.content_url, a.read_num FROM - articles a + articles a LEFT JOIN - gzhs g ON g.biz = a.biz + gzhs g ON g.biz = a.biz WHERE - pub_date > '{year}' - AND - g.biz = 'MzIzMDU4Njg3MA==' + pub_year = '{year}' + AND + g.biz in ({', '.join([f"'{biz}'" for biz in df_fx["公众号Biz"].tolist()])}) ORDER BY - pub_date + pub_year, pub_month, pub_day; ''' - df = pd.read_sql_query(query, conn) - # 关闭数据库连接 - conn.close() + df = pd.read_sql_query(query_gzhs, conn) + conn.close + + # 追加总院数据来源 + for ind, row in df.iterrows(): - id = row['id'] - full_path = os.path.join(wechat_dir, row['nickname'], row['id'] + '.md') - try: - with open(full_path, encoding='utf-8') as f: - content = f.read() - # 从content中获取来源 - a_match = re.findall('来源丨(.*?)\n', content) - a_list = [] - if a_match: - # a = a_match[0].replace('\xa0', '、').replace(' ', '、') - # a = re.sub(r'、+', '、', a) - a = re.sub(r'[\xa0\s]+', '、', a_match[0]) - df.at[ind, 'source'] = a - except FileNotFoundError: - print(full_path + '---不存在') - # 填充到execl中 + if row['gbiz'] == zybiz: + full_path = os.path.join(wechat_dir, row['nickname'], row['id'] + '.md') + try: + with open(full_path, encoding='utf-8') as f: + content = f.read() + # 从content中获取来源 + a_match = re.findall('来源丨(.*?)\n', content) + if a_match: + # a = a_match[0].replace('\xa0', '、').replace(' ', '、') + # a = re.sub(r'、+', '、', a) + a = re.sub(r'[\xa0\s]+', '、', a_match[0].strip()) + df.at[ind, 'source'] = a + except FileNotFoundError: + print(full_path + '---不存在') + df['source'] = df['source'].fillna('') + # df_fx['供总院稿数'] = df_fx['单位'].apply(lambda unit: (df['source'].str.contains(unit)).sum()) + # df_fx['供总院专稿数'] = df_fx['单位'].apply(lambda unit: (df['source'] == unit).sum()) + # df_fx['供总院组稿数'] = df_fx['单位'].apply(lambda unit: ((df['source'].str.contains(unit)&(df['source']!=unit))).sum()) + # df_fx['供总院阅读10000及以上数'] = df_fx['单位'].apply(lambda unit: ((df['read_num']>=10000)&(df['source'].str.contains(unit))).sum()) + # df_fx['供总院阅读5000及以上数'] = df_fx['单位'].apply(lambda unit: ((df['read_num']>=5000)&(df['read_num']<10000)&(df['source'].str.contains(unit))).sum()) + # df_fx['供总院阅读1000及以上数'] = df_fx['单位'].apply(lambda unit: ((df['read_num']>=1000)&(df['read_num']<5000)&(df['source'].str.contains(unit))).sum()) + # df_fx['1月发布数'] = df_fx['公众号Biz'].apply(lambda unit: ((df['pub_year']==year)&(df['pub_month']=='01')&(df['gbiz']==unit)).sum() if unit else '') + + # 更详细的分析 + for ind, row in df_fx.iterrows(): + dw = row['单位'] + gbiz = row['公众号Biz'] + + # 全年对总院供给统计 + # if '、' in dw: # 针对这种同一部门的 + # cons = (df['gbiz']==zybiz) + # cons_dw_1 = pd.Series(False, index=df.index) + # for item in dw.split('、'): + # cons_dw_1 = (df['source'].str.contains(item))|cons_dw_1 + # df_fx.at[ind, '供总院全年稿数'] = ((cons_dw_1)&(cons)).sum() + # else: + # df_fx.at[ind, '供总院全年稿数'] = ((df['source'].str.contains(dw))&(df['gbiz']==zybiz)).sum() + df_fx.at[ind, '供总院全年专稿数'] = ((df['source'] == dw)&(df['gbiz']==zybiz)).sum() + df_fx.at[ind, '供总院全年组稿数'] = ((df['source'].str.contains(dw)&(df['source']!=dw))&(df['gbiz']==zybiz)).sum() + df_fx.at[ind, '供总院全年阅读10000及以上数'] = ((df['read_num']>=10000)&(df['source'].str.contains(dw))&(df['gbiz']==zybiz)).sum() + df_fx.at[ind, '供总院全年阅读5000及以上数'] = ((df['read_num']>=5000)&(df['read_num']<10000)&(df['source'].str.contains(dw))&(df['gbiz']==zybiz)).sum() + df_fx.at[ind, '供总院全年阅读1000及以上数'] = ((df['read_num']>=1000)&(df['read_num']<5000)&(df['source'].str.contains(dw))&(df['gbiz']==zybiz)).sum() + + for i in ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月', '上半年', '下半年', '全年']: + if '月' in i: + i_str = i.replace('月', '').zfill(2) + cons_y_m = (df['pub_month']==str(i_str)) + elif i == '上半年': + cons_y_m = (df['pub_month'] =='01')|(df['pub_month'] =='02')|(df['pub_month'] =='03')|(df['pub_month'] =='04')|(df['pub_month'] =='05')|(df['pub_month'] =='06') + elif i == '下半年': + cons_y_m = (df['pub_month'] =='07')|(df['pub_month'] =='08')|(df['pub_month'] =='09')|(df['pub_month'] =='10')|(df['pub_month'] =='11')|(df['pub_month'] =='12') + elif i == '全年': + cons_y_m = pd.Series(True, index=df.index) + + if '、' in dw: # 针对这种同一部门的 + cons_dw_1 = pd.Series(False, index=df.index) + for item in dw.split('、'): + cons_dw_1 = (df['source'].str.contains(item))|cons_dw_1 + df_fx.at[ind, f'供总院{i}稿数'] = ((cons_dw_1)&(cons_y_m)&(df['gbiz']==zybiz)).sum() + else: + df_fx.at[ind, f'供总院{i}稿数'] = (df['source'].str.contains(dw)&(cons_y_m)&(df['gbiz']==zybiz)).sum() + df_fx[f'供总院{i}稿数'] = df_fx[f'供总院{i}稿数'].fillna(0) + df_fx[f'供总院{i}稿数'] = df_fx[f'供总院{i}稿数'].astype(int) + + if gbiz: + # 进行查询 + # 条件 + cons = (cons_y_m)&(df['gbiz']==gbiz) + cons_sum = (cons).sum() + df_fx.at[ind, f'{i}发布数'] = cons_sum + df_fx[f'{i}发布数'] = df_fx[f'{i}发布数'].fillna(0) + df_fx[f'{i}发布数'] = df_fx[f'{i}发布数'].astype(int) + df_fx.at[ind, f'{i}最高点击文章'] = '' + if cons_sum: + max_read_row = df[cons].loc[df[cons]['read_num'].idxmax()] + max_read_row_list = [max_read_row['id'], max_read_row['title'], str(max_read_row['read_num']), f'{max_read_row["pub_year"]}-{max_read_row["pub_month"]}-{max_read_row["pub_day"]}', max_read_row['source']] + df_fx.at[ind, f'{i}最高点击文章'] = '***'.join(max_read_row_list) + + # 矫正数据类型 + df_fx = df_fx.applymap(float_to_int) + # 先输出原始统计数据 + origin_path = os.path.join(BASE_DIR, f'summary/{year}_fx.xlsx') + df_fx.to_excel(origin_path, index=True) + + # 追加到总院年分析表中 template_path = os.path.join(BASE_DIR, 'summary/template_cbma.xlsx') workbook = load_workbook(template_path) sheet = workbook['公众号更新数'] sheet.cell(row=1, column=1, value=f'关于{year}年度中国建材总院新媒体更新情况明细表\n(官微)') + ind_zy = 0 for ind, row in df.iterrows(): - sheet.cell(row=ind+3, column=1, value=str(ind+1)) - sheet.cell(row=ind+3, column=2, value=row['pub_date']) - sheet.cell(row=ind+3, column=3, value=row['title']) - sheet.cell(row=ind+3, column=4, value=row['source']) - sheet.cell(row=ind+3, column=6, value=row['read_num']) - sheet.cell(row=ind+3, column=7, value=row['content_url']) - output_path = os.path.join(BASE_DIR, f'summary/{year}年_cbma.xlsx') - workbook.save(output_path) - # 开始统计分数 - t_1 = (df['source'].str.contains('瑞泰科技')).sum() - t_2 = (df['source'].str.contains('国检集团')).sum() - t_3 = (df['source'].str.contains('中材高新')).sum() - t_4 = (df['source'].str.contains('哈玻院')).sum() - t_5 = (df['source'].str.contains('中国新材院')).sum() - t_6 = (df['source'].str.contains('秦皇岛院')).sum() - t_7 = (df['source'].str.contains('西安墙材院')).sum() - t_8 = (df['source'].str.contains('咸阳陶瓷院')).sum() - t_9 = (df['source'].str.contains('钟表所')).sum() - t_10 = (df['source'].str.contains('总院北分')).sum() - t_11 = (df['source'].str.contains('中岩科技')).sum() - t_12 = (df['source'].str.contains('水泥新材院')).sum() - t_13 = (df['source'].str.contains('中建材科创院')).sum() - t_14 = (df['source'].str.contains('科建苑')).sum() + if row['gbiz'] == zybiz: + sheet.cell(row=ind_zy+3, column=1, value=str(ind_zy+1)) + sheet.cell(row=ind_zy+3, column=2, value=f'{row["pub_year"]}-{row["pub_month"]}-{row["pub_day"]}') + sheet.cell(row=ind_zy+3, column=3, value=row['title']) + sheet.cell(row=ind_zy+3, column=4, value=row['source']) + sheet.cell(row=ind_zy+3, column=6, value=row['read_num']) + sheet.cell(row=ind_zy+3, column=7, value=row['id']) + sheet.cell(row=ind_zy+3, column=8, value=row['content_url']) + ind_zy = ind_zy + 1 + cbma_path = os.path.join(BASE_DIR, f'summary/{year}年_cbma.xlsx') + workbook.save(cbma_path) + print(f'总院{year}年文章表生成完毕!') + template_cal_path = os.path.join(BASE_DIR, 'summary/tempalte_cbma_cal.xlsx') workbook2 = load_workbook(template_cal_path) + need_df_list = [ "瑞泰科技", "国检集团", "中材高新", "哈玻院", "中国新材院", "秦皇岛院", "西安墙材院", "咸阳陶瓷院", "钟表所", "总院北分", "中岩科技", "水泥新材院", "中建材科创院", "科建苑"] sheet2= workbook2['打分表'] sheet2.cell(row=1, column=1, value=f'中国建材总院宣传工作计分表({year}年度)') - sheet2.cell(row=6, column=5, value=t_1) - sheet2.cell(row=6, column=7, value=t_2) - sheet2.cell(row=6, column=9, value=t_3) - sheet2.cell(row=6, column=11, value=t_4) - sheet2.cell(row=6, column=13, value=t_5) - sheet2.cell(row=6, column=15, value=t_6) - sheet2.cell(row=6, column=17, value=t_7) - sheet2.cell(row=6, column=19, value=t_8) - sheet2.cell(row=6, column=21, value=t_9) - sheet2.cell(row=6, column=23, value=t_10) - sheet2.cell(row=6, column=25, value=t_11) - sheet2.cell(row=6, column=27, value=t_12) - sheet2.cell(row=6, column=29, value=t_13) - sheet2.cell(row=6, column=31, value=t_14) - output_path2 = os.path.join(BASE_DIR, f'summary/{year}年_cbma_cal.xlsx') - workbook2.save(output_path2) - return output_path, output_path2 + for ind, val in enumerate(need_df_list): + row_ind_df_fx = df_fx['单位'].to_list().index(val) + sheet2.cell(row=6, column=5+2*ind, value=df_fx.at[row_ind_df_fx, '供总院全年专稿数']) + sheet2.cell(row=10, column=5+2*ind, value=df_fx.at[row_ind_df_fx, '供总院全年组稿数']) + sheet2.cell(row=12, column=5+2*ind, value=df_fx.at[row_ind_df_fx, '供总院全年阅读10000及以上数']) + sheet2.cell(row=13, column=5+2*ind, value=df_fx.at[row_ind_df_fx, '供总院全年阅读5000及以上数']) + sheet2.cell(row=14, column=5+2*ind, value=df_fx.at[row_ind_df_fx, '供总院全年阅读1000及以上数']) + cbma_cal_path = os.path.join(BASE_DIR, f'summary/{year}年_cbma_cal.xlsx') + workbook2.save(cbma_cal_path) + print(f'总院{year}年打分表生成完毕!') + + # need_df_list_full = [ "瑞泰科技股份有限公司", "中国国检测试控股集团股份有限公司", "中材高新材料股份有限公司", "哈尔滨玻璃钢研究院有限公司", "中国新型建材设计研究院有限公司", "秦皇岛玻璃工业研究设计院有限公司", "西安墙体材料研究设计院有限公司", "咸阳陶瓷研究设计院有限公司", "西安轻工业钟表研究所有限公司", "中国建材总院北京分公司", "中建材中岩科技有限公司", "水泥科学与新型建筑材料研究院(中研益)", "中建材科创新技术研究院(山东)有限公司", "北京科建苑物业管理有限公司"] + dw_list = df_fx['单位'].to_list() + template_month_path = os.path.join(BASE_DIR, 'summary/template_month.xlsx') + workbook3 = load_workbook(template_month_path) + for i in ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月', '上半年', '下半年', '全年']: + try: + sheet= workbook3[i] + except KeyError: + sheet = workbook3.copy_worksheet(workbook3['1月']) + sheet.title = i + sheet.cell(row=1, column=1, value=f'关于{year}年度中国建材总院各企业新媒体更新情况统计表\n({i})') + # 开始总院填充数据 + sheet.cell(row=4, column=3, value=df_fx.at[0, f'{i}发布数']) + max_read_row = df_fx.at[dw_list.index('中国建材总院'), f'{i}最高点击文章'] + if max_read_row: + _, title, read_num, pub_date, source = max_read_row.split('***') + sheet.cell(row=7, column=2, value=title) + sheet.cell(row=7, column=4, value=read_num) + sheet.cell(row=7, column=5, value=pub_date) + sheet.cell(row=7, column=6, value=source) + # 开始填充各单位数据 + sheet.cell(row=14, column=3, value=df_fx.at[dw_list.index('瑞泰科技'), f'{i}发布数']) + sheet.cell(row=14, column=6, value=df_fx.at[dw_list.index('瑞泰科技'), f'供总院{i}稿数']) + + sheet.cell(row=15, column=3, value=df_fx.at[dw_list.index('国检集团'), f'{i}发布数']) + sheet.cell(row=15, column=6, value=df_fx.at[dw_list.index('国检集团'), f'供总院{i}稿数']) + + sheet.cell(row=16, column=3, value=df_fx.at[dw_list.index('中材高新'), f'{i}发布数']) + sheet.cell(row=16, column=6, value=df_fx.at[dw_list.index('中材高新'), f'供总院{i}稿数']) + + sheet.cell(row=17, column=3, value=df_fx.at[dw_list.index('哈玻院'), f'{i}发布数']) + sheet.cell(row=17, column=6, value=df_fx.at[dw_list.index('哈玻院'), f'供总院{i}稿数']) + + sheet.cell(row=18, column=3, value=df_fx.at[dw_list.index('中国新材院'), f'{i}发布数']) + sheet.cell(row=18, column=6, value=df_fx.at[dw_list.index('中国新材院'), f'供总院{i}稿数']) + + sheet.cell(row=19, column=3, value=df_fx.at[dw_list.index('秦皇岛院'), f'{i}发布数']) + sheet.cell(row=19, column=6, value=df_fx.at[dw_list.index('秦皇岛院'), f'供总院{i}稿数']) + + sheet.cell(row=20, column=3, value=df_fx.at[dw_list.index('西安墙材院'), f'{i}发布数']) + sheet.cell(row=20, column=6, value=df_fx.at[dw_list.index('西安墙材院'), f'供总院{i}稿数']) + + sheet.cell(row=21, column=3, value=df_fx.at[dw_list.index('咸阳陶瓷院'), f'{i}发布数']) + sheet.cell(row=21, column=6, value=df_fx.at[dw_list.index('咸阳陶瓷院'), f'供总院{i}稿数']) + + sheet.cell(row=22, column=3, value=df_fx.at[dw_list.index('钟表所'), f'{i}发布数']) + sheet.cell(row=22, column=6, value=df_fx.at[dw_list.index('钟表所'), f'供总院{i}稿数']) + + # sheet.cell(row=23, column=3, value=df_fx.at[dw_list.index('总院北分'), f'{i}发布数']) + sheet.cell(row=23, column=6, value=df_fx.at[dw_list.index('总院北分'), f'供总院{i}稿数']) + + sheet.cell(row=24, column=3, value=df_fx.at[dw_list.index('中岩科技'), f'{i}发布数']) + sheet.cell(row=24, column=6, value=df_fx.at[dw_list.index('中岩科技'), f'供总院{i}稿数']) + + sheet.cell(row=25, column=3, value=df_fx.at[dw_list.index('水泥新材院'), f'{i}发布数']) + sheet.cell(row=25, column=6, value=df_fx.at[dw_list.index('水泥新材院'), f'供总院{i}稿数']) + + # sheet.cell(row=26, column=3, value=df_fx.at[dw_list.index('中建材科创院'), f'{i}发布数']) + sheet.cell(row=26, column=6, value=df_fx.at[dw_list.index('中建材科创院'), f'供总院{i}稿数']) + + # sheet.cell(row=27, column=3, value=df_fx.at[dw_list.index('科建苑'), f'{i}发布数']) + sheet.cell(row=27, column=6, value=df_fx.at[dw_list.index('科建苑'), f'供总院{i}稿数']) + + sheet.cell(row=29, column=2, value=df_fx.at[dw_list.index('办公室(董事会办公室)'), f'供总院{i}稿数']) + sheet.cell(row=30, column=2, value=df_fx.at[dw_list.index('党委组织部/人力资源部'), f'供总院{i}稿数']) + sheet.cell(row=31, column=2, value=df_fx.at[dw_list.index('财务部'), f'供总院{i}稿数']) + sheet.cell(row=32, column=2, value=df_fx.at[dw_list.index('科技部'), f'供总院{i}稿数']) + sheet.cell(row=33, column=2, value=df_fx.at[dw_list.index('投资部'), f'供总院{i}稿数']) + sheet.cell(row=29, column=7, value=df_fx.at[dw_list.index('企业管理部、安全环保部'), f'供总院{i}稿数']) + sheet.cell(row=30, column=7, value=df_fx.at[dw_list.index('党群部/宣传统战部'), f'供总院{i}稿数']) + sheet.cell(row=31, column=7, value=df_fx.at[dw_list.index('党风办/巡察办、纪委综合室'), f'供总院{i}稿数']) + sheet.cell(row=32, column=7, value=df_fx.at[dw_list.index('监督执纪室'), f'供总院{i}稿数']) + sheet.cell(row=33, column=7, value=df_fx.at[dw_list.index('审计办公室'), f'供总院{i}稿数']) + + + cbma_month_path = os.path.join(BASE_DIR, f'summary/{year}年_cbma_month.xlsx') + workbook3.save(cbma_month_path) + print(f'总院{year}年月度表生成完毕!') + + return origin_path, cbma_path, cbma_cal_path, cbma_month_path def make_wechat_articles_full(): diff --git a/start.ico b/start.ico deleted file mode 100644 index 2778f63..0000000 Binary files a/start.ico and /dev/null differ diff --git a/start.py b/start.py index f575fdd..6cc1285 100644 --- a/start.py +++ b/start.py @@ -87,33 +87,38 @@ class AnaThread(QThread): now = datetime.datetime.now() self.update_signal.emit({'msg': '对比开始...'}) self.update_signal.emit({'msg': '正在组合微信公众号爬取内容...'}) - make_simple_csv_from_db() + make_simple_csv_from_db(now) make_wechat_articles_full() self.update_signal.emit({'msg': "公众号爬取内容组装完毕!"}) self.update_signal.emit({'msg': '开始对比分析所有内容...'}) wechat_results = ana_wechat() web_results = ana_web() - # 生成汇总表 - self.update_signal.emit({'msg': '开始生成汇总表...'}) - output_excel_path = os.path.join(BASE_DIR, f'summary/{now.year}年{now.month}月-分析结果汇总表.xlsx') - workbook = load_workbook(TEMPLATE_PATH) - wechat_sheet = workbook['公众号'] - web_sheet = workbook['网站'] - for row in wechat_results: - wechat_sheet.append(row) - for row in web_results: - web_sheet.append(row) - workbook.save(output_excel_path) - workbook.close() - # with open('w1.json', 'w', encoding='utf-8') as f: - # f.write(json.dumps(wechat_results, ensure_ascii=False)) + try: + # 生成汇总表 + self.update_signal.emit({'msg': '开始生成汇总表...'}) + output_excel_path = os.path.join(BASE_DIR, f'summary/{now.year}年{now.month}月-分析结果汇总表.xlsx') + workbook = load_workbook(TEMPLATE_PATH) + wechat_sheet = workbook['公众号'] + web_sheet = workbook['网站'] + for row in wechat_results: + wechat_sheet.append(row) + for row in web_results: + web_sheet.append(row) + workbook.save(output_excel_path) + workbook.close() + # with open('w1.json', 'w', encoding='utf-8') as f: + # f.write(json.dumps(wechat_results, ensure_ascii=False)) - # with open('w2.json', 'w', encoding='utf-8') as f: - # f.write(json.dumps(web_results, ensure_ascii=False)) - # 生成简报 - self.update_signal.emit({'msg': '开始生成汇总简报...'}) - output_report_path = gen_doc(wechat_results, web_results) - self.update_signal.emit({'msg': '分析完毕, 请查看结果栏, 可手动校对', 'output_excel_path': output_excel_path, 'output_report_path': output_report_path}) + # with open('w2.json', 'w', encoding='utf-8') as f: + # f.write(json.dumps(web_results, ensure_ascii=False)) + # 生成简报 + self.update_signal.emit({'msg': '开始生成汇总简报...'}) + output_report_path = gen_doc(wechat_results, web_results) + self.update_signal.emit({'msg': '分析完毕, 请查看结果栏, 可手动校对', 'output_excel_path': output_excel_path, 'output_report_path': output_report_path}) + except PermissionError as e: + self.update_signal.emit({'msg': str(e)}) + self.update_signal.emit({'msg': '文件被占用请先关闭!'}) + raise def run(self) -> None: try: @@ -209,6 +214,8 @@ class MainWindow(QMainWindow): self.ui.bCal.clicked.connect(self.cbma_cal) self.ui.bOpenCalRes1.clicked.connect(lambda: self.open_file(self.ui.lCalRes1.text())) self.ui.bOpenCalRes2.clicked.connect(lambda: self.open_file(self.ui.lCalRes2.text())) + self.ui.bOpenCalRes3.clicked.connect(lambda: self.open_file(self.ui.lCalRes3.text())) + self.ui.bOpenCalRes4.clicked.connect(lambda: self.open_file(self.ui.lCalRes4.text())) self.ui.vLog.setModel(self.logModel) self.res1Workbook = None @@ -268,9 +275,16 @@ class MainWindow(QMainWindow): def cbma_cal(self): now_year = datetime.datetime.now().year self.update_log({'msg': '正在分析本年总院官微数据...'}) - output_path, output_path2 = get_cbma_info_from_db_and_ana(now_year) - self.ui.lCalRes1.setText(output_path) - self.ui.lCalRes2.setText(output_path2) + try: + origin_path, cbma_path, cbma_cal_path, cbma_month_path = get_cbma_info_from_db_and_ana(now_year) + except PermissionError as e: + self.update_log({'msg': str(e)}) + self.update_log({'msg': '文件被占用请先关闭!'}) + raise + self.ui.lCalRes1.setText(origin_path) + self.ui.lCalRes2.setText(cbma_path) + self.ui.lCalRes3.setText(cbma_cal_path) + self.ui.lCalRes4.setText(cbma_month_path) self.update_log({'msg': '分析完毕!'}) def update_log(self, rdict): @@ -312,7 +326,7 @@ class MainWindow(QMainWindow): if __name__ == "__main__": - # gen_doc() + # pyside6-uic main.ui -o ui_mainwindow.py print('正在启动程序...') app = MyApplication(sys.argv) main_window = app.createMainWindow() diff --git a/summary/template_cbma.xlsx b/summary/template_cbma.xlsx index 9bd26a7..06b9964 100644 Binary files a/summary/template_cbma.xlsx and b/summary/template_cbma.xlsx differ diff --git a/summary/template_month.xlsx b/summary/template_month.xlsx new file mode 100644 index 0000000..e7ec7f0 Binary files /dev/null and b/summary/template_month.xlsx differ diff --git a/ui_mainwindow.py b/ui_mainwindow.py index 72fa742..106f083 100644 --- a/ui_mainwindow.py +++ b/ui_mainwindow.py @@ -23,16 +23,16 @@ class Ui_MainWindow(object): def setupUi(self, MainWindow): if not MainWindow.objectName(): MainWindow.setObjectName(u"MainWindow") - MainWindow.resize(600, 830) + MainWindow.resize(600, 850) sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth()) MainWindow.setSizePolicy(sizePolicy) - MainWindow.setMinimumSize(QSize(600, 830)) - MainWindow.setMaximumSize(QSize(600, 830)) + MainWindow.setMinimumSize(QSize(600, 850)) + MainWindow.setMaximumSize(QSize(600, 850)) icon = QIcon() - icon.addFile(u"start.ico", QSize(), QIcon.Normal, QIcon.Off) + icon.addFile(u"favicon.ico", QSize(), QIcon.Normal, QIcon.Off) MainWindow.setWindowIcon(icon) MainWindow.setAutoFillBackground(False) self.centralwidget = QWidget(MainWindow) @@ -44,7 +44,7 @@ class Ui_MainWindow(object): self.label.setScaledContents(True) self.groupBox = QGroupBox(self.centralwidget) self.groupBox.setObjectName(u"groupBox") - self.groupBox.setGeometry(QRect(10, 280, 191, 91)) + self.groupBox.setGeometry(QRect(10, 280, 191, 81)) font = QFont() font.setPointSize(11) self.groupBox.setFont(font) @@ -65,7 +65,7 @@ class Ui_MainWindow(object): self.label_5.setStyleSheet(u"color: red;") self.groupBox_5 = QGroupBox(self.centralwidget) self.groupBox_5.setObjectName(u"groupBox_5") - self.groupBox_5.setGeometry(QRect(10, 540, 581, 121)) + self.groupBox_5.setGeometry(QRect(10, 510, 581, 121)) self.groupBox_5.setFont(font) self.label_7 = QLabel(self.groupBox_5) self.label_7.setObjectName(u"label_7") @@ -122,7 +122,7 @@ class Ui_MainWindow(object): self.bAna.setStyleSheet(u"background-color:#409EFF; color: white; border-radius: 2px") self.label_9 = QLabel(self.centralwidget) self.label_9.setObjectName(u"label_9") - self.label_9.setGeometry(QRect(150, 0, 291, 31)) + self.label_9.setGeometry(QRect(390, 0, 211, 31)) font6 = QFont() font6.setFamilies([u"\u6977\u4f53"]) font6.setPointSize(12) @@ -134,16 +134,16 @@ class Ui_MainWindow(object): self.label_9.setMargin(6) self.groupBox_6 = QGroupBox(self.centralwidget) self.groupBox_6.setObjectName(u"groupBox_6") - self.groupBox_6.setGeometry(QRect(220, 280, 371, 251)) + self.groupBox_6.setGeometry(QRect(220, 280, 371, 231)) self.groupBox_6.setFont(font) self.vLog = QListView(self.groupBox_6) self.vLog.setObjectName(u"vLog") - self.vLog.setGeometry(QRect(10, 20, 351, 221)) + self.vLog.setGeometry(QRect(10, 20, 351, 201)) self.vLog.setFont(font3) self.vLog.setStyleSheet(u"") self.groupBox_2 = QGroupBox(self.centralwidget) self.groupBox_2.setObjectName(u"groupBox_2") - self.groupBox_2.setGeometry(QRect(10, 380, 191, 151)) + self.groupBox_2.setGeometry(QRect(10, 370, 191, 141)) self.groupBox_2.setFont(font) self.bWebSite = QPushButton(self.groupBox_2) self.bWebSite.setObjectName(u"bWebSite") @@ -170,7 +170,7 @@ class Ui_MainWindow(object): self.bStart.setStyleSheet(u"background-color:#409EFF; color: white; border-radius: 2px") self.groupBox_7 = QGroupBox(self.centralwidget) self.groupBox_7.setObjectName(u"groupBox_7") - self.groupBox_7.setGeometry(QRect(10, 670, 581, 111)) + self.groupBox_7.setGeometry(QRect(10, 630, 581, 171)) self.groupBox_7.setFont(font) self.label_10 = QLabel(self.groupBox_7) self.label_10.setObjectName(u"label_10") @@ -178,7 +178,7 @@ class Ui_MainWindow(object): self.label_10.setFont(font2) self.label_11 = QLabel(self.groupBox_7) self.label_11.setObjectName(u"label_11") - self.label_11.setGeometry(QRect(10, 80, 91, 16)) + self.label_11.setGeometry(QRect(10, 90, 91, 16)) self.label_11.setFont(font2) self.line_2 = QFrame(self.groupBox_7) self.line_2.setObjectName(u"line_2") @@ -187,11 +187,11 @@ class Ui_MainWindow(object): self.line_2.setFrameShadow(QFrame.Sunken) self.lCalRes1 = QLabel(self.groupBox_7) self.lCalRes1.setObjectName(u"lCalRes1") - self.lCalRes1.setGeometry(QRect(110, 55, 381, 21)) + self.lCalRes1.setGeometry(QRect(110, 60, 391, 21)) self.lCalRes1.setFont(font3) self.lCalRes2 = QLabel(self.groupBox_7) self.lCalRes2.setObjectName(u"lCalRes2") - self.lCalRes2.setGeometry(QRect(110, 80, 381, 16)) + self.lCalRes2.setGeometry(QRect(110, 90, 401, 16)) self.lCalRes2.setFont(font3) self.bOpenCalRes1 = QPushButton(self.groupBox_7) self.bOpenCalRes1.setObjectName(u"bOpenCalRes1") @@ -205,6 +205,38 @@ class Ui_MainWindow(object): self.bCal.setGeometry(QRect(20, 30, 151, 24)) self.bCal.setFont(font) self.bCal.setStyleSheet(u"background-color:#409EFF; color: white; border-radius: 2px") + self.bOpenCalRes3 = QPushButton(self.groupBox_7) + self.bOpenCalRes3.setObjectName(u"bOpenCalRes3") + self.bOpenCalRes3.setGeometry(QRect(520, 110, 51, 24)) + self.label_12 = QLabel(self.groupBox_7) + self.label_12.setObjectName(u"label_12") + self.label_12.setGeometry(QRect(10, 120, 91, 16)) + self.label_12.setFont(font2) + self.lCalRes3 = QLabel(self.groupBox_7) + self.lCalRes3.setObjectName(u"lCalRes3") + self.lCalRes3.setGeometry(QRect(110, 120, 401, 16)) + self.lCalRes3.setFont(font3) + self.line_3 = QFrame(self.groupBox_7) + self.line_3.setObjectName(u"line_3") + self.line_3.setGeometry(QRect(10, 100, 561, 16)) + self.line_3.setFrameShape(QFrame.HLine) + self.line_3.setFrameShadow(QFrame.Sunken) + self.line_4 = QFrame(self.groupBox_7) + self.line_4.setObjectName(u"line_4") + self.line_4.setGeometry(QRect(10, 130, 561, 16)) + self.line_4.setFrameShape(QFrame.HLine) + self.line_4.setFrameShadow(QFrame.Sunken) + self.label_13 = QLabel(self.groupBox_7) + self.label_13.setObjectName(u"label_13") + self.label_13.setGeometry(QRect(10, 150, 91, 16)) + self.label_13.setFont(font2) + self.bOpenCalRes4 = QPushButton(self.groupBox_7) + self.bOpenCalRes4.setObjectName(u"bOpenCalRes4") + self.bOpenCalRes4.setGeometry(QRect(520, 140, 51, 24)) + self.lCalRes4 = QLabel(self.groupBox_7) + self.lCalRes4.setObjectName(u"lCalRes4") + self.lCalRes4.setGeometry(QRect(110, 150, 401, 16)) + self.lCalRes4.setFont(font3) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QMenuBar(MainWindow) self.menubar.setObjectName(u"menubar") @@ -220,7 +252,7 @@ class Ui_MainWindow(object): # setupUi def retranslateUi(self, MainWindow): - MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"\u4e2d\u56fd\u5efa\u6750\u603b\u9662\u5ba3\u4f20\u5de5\u4f5c\u4fe1\u606f\u5316\u7ba1\u7406\u5e73\u53f0", None)) + MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"\u4e2d\u56fd\u5efa\u6750\u603b\u9662\u4fe1\u606f\u7edf\u8ba1\u5e73\u53f0", None)) self.label.setText("") self.groupBox.setTitle(QCoreApplication.translate("MainWindow", u"1.\u5fae\u4fe1\u516c\u4f17\u53f7\u4fe1\u606f\u6293\u53d6", None)) self.bWechat.setText(QCoreApplication.translate("MainWindow", u"\u6253\u5f00\u5de5\u5177", None)) @@ -235,7 +267,7 @@ class Ui_MainWindow(object): self.bBiao.setText(QCoreApplication.translate("MainWindow", u"\u6253\u5f00\u5206\u6790\u6807\u51c6Excel", None)) self.label_4.setText(QCoreApplication.translate("MainWindow", u"\u8bf7\u5728\u4fee\u6539\u540e\u4fdd\u5b58\u5e76\u5173\u95ed", None)) self.bAna.setText(QCoreApplication.translate("MainWindow", u"\u5f00\u59cb\u5206\u6790", None)) - self.label_9.setText(QCoreApplication.translate("MainWindow", u"\u4e2d\u56fd\u5efa\u6750\u603b\u9662\u5ba3\u4f20\u5de5\u4f5c\u4fe1\u606f\u5316\u7ba1\u7406\u5e73\u53f0", None)) + self.label_9.setText(QCoreApplication.translate("MainWindow", u"\u4e2d\u56fd\u5efa\u6750\u603b\u9662\u4fe1\u606f\u7edf\u8ba1\u5e73\u53f0", None)) self.groupBox_6.setTitle(QCoreApplication.translate("MainWindow", u"\u64cd\u4f5c\u65e5\u5fd7\u663e\u793a", None)) self.groupBox_2.setTitle(QCoreApplication.translate("MainWindow", u"2.\u786e\u8ba4\u9700\u8981\u722c\u53d6\u7684\u5b98\u7f51", None)) self.bWebSite.setText(QCoreApplication.translate("MainWindow", u"\u6253\u5f00\u7f51\u7ad9\u5217\u8868Excel", None)) @@ -245,12 +277,18 @@ class Ui_MainWindow(object): self.lSize.setText(QCoreApplication.translate("MainWindow", u"5", None)) self.bStart.setText(QCoreApplication.translate("MainWindow", u"\u5f00\u59cb\u722c\u53d6", None)) self.groupBox_7.setTitle(QCoreApplication.translate("MainWindow", u"\u603b\u9662\u5b98\u5fae", None)) - self.label_10.setText(QCoreApplication.translate("MainWindow", u"\u6c47\u603b\u7ed3\u679cExcel:", None)) - self.label_11.setText(QCoreApplication.translate("MainWindow", u"\u6c47\u603b\u6253\u5206Excel:", None)) + self.label_10.setText(QCoreApplication.translate("MainWindow", u"\u5206\u6790\u6c47\u603b\u6570\u636e", None)) + self.label_11.setText(QCoreApplication.translate("MainWindow", u"\u603b\u9662\u5e74\u5ea6\u6587\u7ae0\u8868", None)) self.lCalRes1.setText("") self.lCalRes2.setText("") self.bOpenCalRes1.setText(QCoreApplication.translate("MainWindow", u"\u6253\u5f00", None)) self.bOpenCalRes2.setText(QCoreApplication.translate("MainWindow", u"\u6253\u5f00", None)) self.bCal.setText(QCoreApplication.translate("MainWindow", u"\u6c47\u603b\u6253\u5206", None)) + self.bOpenCalRes3.setText(QCoreApplication.translate("MainWindow", u"\u6253\u5f00", None)) + self.label_12.setText(QCoreApplication.translate("MainWindow", u"\u603b\u9662\u5e74\u5ea6\u6253\u5206\u8868", None)) + self.lCalRes3.setText("") + self.label_13.setText(QCoreApplication.translate("MainWindow", u"\u5355\u4f4d\u6708\u5ea6\u7edf\u8ba1\u8868", None)) + self.bOpenCalRes4.setText(QCoreApplication.translate("MainWindow", u"\u6253\u5f00", None)) + self.lCalRes4.setText("") # retranslateUi diff --git a/宣传信息统计.exe b/宣传信息统计.exe new file mode 100644 index 0000000..28d7e8e Binary files /dev/null and b/宣传信息统计.exe differ