Skip to content

Commit b9dc043

Browse files
committed
Finish 0020
1 parent a76774e commit b9dc043

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

JiYouMCC/0020/0020-result.PNG

16.1 KB
Loading

JiYouMCC/0020/0020.PNG

46.8 KB
Loading

JiYouMCC/0020/0020.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# -*- coding: utf-8 -*-
2+
import xlrd
3+
import datetime
4+
5+
infos = []
6+
info_file = xlrd.open_workbook('examples.xls')
7+
info_table = info_file.sheets()[0]
8+
row_count = info_table.nrows
9+
for row in range(7, row_count):
10+
time_string = info_table.cell(row, 4).value
11+
time_s_sp = time_string.split(':')
12+
infos.append(
13+
{
14+
'type': info_table.cell(row, 2).value,
15+
'number': info_table.cell(row, 3).value,
16+
'timespan': datetime.timedelta(
17+
seconds=int(time_s_sp[2]),
18+
minutes=int(time_s_sp[1]),
19+
hours=int(time_s_sp[0])),
20+
'class': info_table.cell(row, 5).value
21+
}
22+
)
23+
24+
time_all = datetime.timedelta(seconds=0)
25+
time_types = {}
26+
time_classes = {}
27+
time_numbers = {}
28+
for infor in infos:
29+
time_all += infor['timespan']
30+
31+
infor_type = infor['type']
32+
if infor_type in time_types:
33+
time_types[infor_type] += infor['timespan']
34+
else:
35+
time_types[infor_type] = infor['timespan']
36+
37+
infor_class = infor['class']
38+
if infor_class in time_classes:
39+
time_classes[infor_class] += infor['timespan']
40+
else:
41+
time_classes[infor_class] = infor['timespan']
42+
43+
infor_number = infor['number']
44+
if infor_number in time_numbers:
45+
time_numbers[infor_number] += infor['timespan']
46+
else:
47+
time_numbers[infor_number] = infor['timespan']
48+
49+
print '总通话时间:%s' % time_all
50+
print
51+
print '通信方式分类:'
52+
for (k, v) in time_types.items():
53+
print k.encode('utf-8'), v
54+
print
55+
print '通信类型分类:'
56+
for (k, v) in time_classes.items():
57+
print k.encode('utf-8'), v
58+
print
59+
print '对方号码分类:'
60+
for (k, v) in time_numbers.items():
61+
print k.ljust(20), v

JiYouMCC/0020/readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
**第 0020 题:** [登陆中国联通网上营业厅](http://iservice.10010.com/index_.html) 后选择「自助服务」 --> 「详单查询」,然后选择你要查询的时间段,点击「查询」按钮,查询结果页面的最下方,点击「导出」,就会生成类似于 2014年10月01日~2014年10月31日通话详单.xls 文件。写代码,对每月通话时间做个统计。
2+
----
3+
1. 我用移动
4+
2. Excel的效果大概是这样的(私人信息已经涂黑):![移动账单Excel](https://raw.githubusercontent.com/JiYouMCC/python/master/JiYouMCC/0020/0020.png)
5+
3. 除了统计通话时间,还能根据通话方式/对方号码/通信类型分类汇总
6+
4. 结果是这样的 ![结果](https://raw.githubusercontent.com/JiYouMCC/python/master/JiYouMCC/0020/0020-result.png "Optional title")

0 commit comments

Comments
 (0)