Skip to content

Commit 782e19d

Browse files
committed
0020:按月统计通话时间
1 parent aa7e12b commit 782e19d

3 files changed

Lines changed: 56 additions & 1 deletion

File tree

xyjxyf/0020/0020.xls

18 KB
Binary file not shown.

xyjxyf/0020/src.xls

-43 KB
Binary file not shown.

xyjxyf/show_me_the_code.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,60 @@ def write_numbers_to_xml(list=None, to_path=None):
447447
number_tree.write(to_path, pretty_print=True, xml_declaration=True, encoding='utf-8')
448448

449449

450+
# 第 0020 题: 登陆中国联通网上营业厅 后选择「自助服务」 --> 「详单查询」,然后选择你要查询的时间段,点击「查询」按钮,
451+
# 查询结果页面的最下方,点击「导出」,就会生成类似于 2014年10月01日~2014年10月31日通话详单.xls 文件。
452+
# 写代码,对每月通话时间做个统计
453+
454+
import datetime
455+
456+
def statistics_month_time():
457+
dic = {}
458+
wb = xlrd.open_workbook("./0020/0020.xls")
459+
sheet = wb.sheets()[0]
460+
row_count = sheet.nrows
461+
462+
for i in range(1, sheet.nrows):
463+
values = sheet.row_values(i)
464+
ym_str = values[2][:6]
465+
466+
time_str = values[3]
467+
if '时' in time_str:
468+
time_str = re.sub('时', '.', time_str)
469+
if '分' in time_str:
470+
time_str = re.sub('分', '.', time_str)
471+
if '秒' in time_str:
472+
time_str = re.sub('秒', '', time_str)
473+
474+
tmp = time_str.split('.')
475+
j = len(tmp) - 1
476+
sum = int(tmp[j])
477+
while j > -1:
478+
sum = sum + (len(tmp) - 1 - j) * 60 * int(tmp[j])
479+
j = j - 1
480+
481+
if ym_str in dic:
482+
dic[ym_str] = dic[ym_str] + int(sum)
483+
else:
484+
dic[ym_str] = int(sum)
485+
486+
# i = i + 1
487+
488+
return dic
489+
490+
491+
# 第 0022 题: iPhone 6、iPhone 6 Plus 早已上市开卖。请查看你写得 第 0005 题的代码是否可以复用
492+
493+
494+
# 第 0023 题: 使用 Python 的 Web 框架,做一个 Web 版本 留言簿 应用
495+
496+
497+
# 第 0024 题: 使用 Python 的 Web 框架,做一个 Web 版本 TodoList 应用
498+
499+
500+
# 第 0025 题: 使用 Python 实现:对着电脑吼一声,自动打开浏览器中的默认网站
501+
502+
503+
450504
if __name__ == "__main__":
451505
# 0000
452506
# add_num(".0000/0000.jpg")
@@ -489,7 +543,7 @@ def write_numbers_to_xml(list=None, to_path=None):
489543
# replace_sensitive_words("./0011/0011.txt", "haha, 北京不错")
490544

491545
# 0013
492-
get_url_imgs("http://www.ivsky.com/tupian/beijing_t1542/index_2.html")
546+
# get_url_imgs("http://www.ivsky.com/tupian/beijing_t1542/index_2.html")
493547

494548
# 0014
495549
# dictxt_to_xls("./0014/student.txt")
@@ -536,6 +590,7 @@ def write_numbers_to_xml(list=None, to_path=None):
536590
# break
537591

538592
# 0020
593+
statistics_month_time()
539594

540595
# 0021
541596

0 commit comments

Comments
 (0)