forked from Show-Me-the-Code/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0020.py
More file actions
32 lines (26 loc) · 1.07 KB
/
0020.py
File metadata and controls
32 lines (26 loc) · 1.07 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''第 0020 题: 登陆中国联通网上营业厅 后选择「自助服务」 --> 「详单查询」,然后选择你要查询的时间段,点击「查询」按钮,查询结果页面的最下方,点击「导出」,就会生成类似于 2014年10月01日~2014年10月31日通话详单.xls 文件。写代码,对每月通话时间做个统计。'''
__author__ = 'Drake-Z'
import os
import re
import xlrd
def jishu(file):
data = xlrd.open_workbook(file)
table = data.sheets()[0]
re_timesec = re.compile(r'([\d]+)秒')
re_timemin = re.compile(r'([\d]+)分')
row_nums = table.nrows
numbers = 0
for i in range(0, row_nums):
a = re_timesec.findall(table.cell(i, 3).value)
b = re_timemin.findall(table.cell(i, 3).value)
if len(a)==0 : pass
else:
numbers += int(a[0])
if len(b)==0 : pass
else:
numbers += int(b[0])*60
print('您本月通话时长总时:%s 分 %s 秒' % (numbers//60, numbers%60))
file = '语音通信.xls'
jishu(file)