微信接龙参与人数统计
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import xlwt
import numpy as np
import os
def to_excel(houseNumber_content, filename):
# 每次先删除test.xls
if os.path.exists(filename):
os.remove(filename)
# 使用numpy把dict类型的houseNumber_content全部写到excel中
# 创建workbook对象
workbook = xlwt.Workbook()
sheet = workbook.add_sheet('sheet1')
# 表头, 第一列房号, 第二列原始参与数据, 第三列签到签字, 第四列签退签字
sheet.write(0, 0, '房号')
sheet.write(0, 1, '原始参与数据')
sheet.write(0, 2, '签到签字')
sheet.write(0, 3, '签退签字')
for i, (key, value) in enumerate(houseNumber_content.items(), start=1):
# 写入excel
sheet.write(i, 0, key)
sheet.write(i, 1, value)
# 保存excel
workbook.save(filename)
def main(filename, excel):
houseNumber_content = {}
money_content = {}
# 按行读取hanwujia.txt文件内容,并将每一行的内容打印出来
keywords = ['去', '到', '参加', '人', '走起']
money = ['金']
with open(filename, 'r') as f:
for line in f.readlines():
line = line.strip('\n') # 去除每行头尾的\n
if line.find("金") != -1:
money = line[line.index('. ') + 2:]
money_house_number = money.split()[0]
money_content[money_house_number] = line
continue
# 如果line内容包含keywords中任意一个, 打印, 并且累加个数
for keyword in keywords:
if line.find(keyword) != -1:
# 如果line包含"不了", 跳过
if line.find("不了") != -1:
continue
if line.find("周末") != -1:
continue
if line.find("外省") != -1:
continue
if line.find("出差") != -1:
continue
if line.find("无法") != -1:
continue
# 找到房号
line1 = line[line.index('. ') + 2:]
line2 = line1.split()[0]
# key是line2, value是line的map
houseNumber_content[line2] = line
# 颜色是红色的
print("\033[31m" + "参加总人数" + "\033[0m", len(houseNumber_content))
print("\033[31m" + "资助总人数" + "\033[0m", len(money_content))
print("\033[31m" + "参加人数详情" + "\033[0m", houseNumber_content)
print("\033[31m" + "资助详情" + "\033[0m", money_content)
if excel:
# to_excel(houseNumber_content, "test.xls")
to_excel(money_content, "资助.xls")
to_excel(houseNumber_content, "参加.xls")
if __name__ == '__main__':
main("jielong", True)
# main("jielong", False)
This post is licensed under CC BY 4.0 by the author.