-
Notifications
You must be signed in to change notification settings - Fork 0
/
r2.py
64 lines (54 loc) · 1.34 KB
/
r2.py
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
#讀取檔案
def read_file(filename):
lines = []
with open(filename, 'r', encoding='utf-8-sig') as f:
for line in f:
lines.append(line.strip())
return lines
#轉換
def convert(lines):
person = None
allen_word_count = 0
allen_sticker_count = 0
allen_image_count = 0
viki_word_count = 0
viki_sticker_count = 0
viki_image_count = 0
for line in lines:
s = line.split(' ')
time = s[0]
name = s[1]
if name == 'Allen':
if s[2] == '貼圖':
allen_sticker_count += 1
elif s[2] == '圖片':
allen_image_count += 1
else:
for m in s[2:]:
allen_word_count += len(m)
elif name == 'Viki':
if s[2] == '貼圖':
viki_sticker_count += 1
elif s[2] == '圖片':
viki_image_count += 1
else:
for m in s[2:]:
viki_word_count +=len(m)
print('allen說了', allen_word_count, '個字')
print('傳了', allen_sticker_count, '個貼圖')
print('傳了', allen_image_count, '張圖片')
print('viki說了', viki_word_count, '個字')
print('傳了', viki_sticker_count, '個貼圖')
print('傳了', viki_image_count, '張圖片')
#print(s)
#寫入檔案
def write_file(filename, lines):
with open(filename, 'w', encoding='utf-8') as f:
for line in lines:
f.write(line + '\n')
#主程式
def main():
lines = read_file('[LINE]Viki.txt')
lines = convert(lines)
# write_file('output.txt', lines)
main()