-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnews-report.py
46 lines (38 loc) · 1.23 KB
/
news-report.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
#!/usr/bin/env python3
''' news report analysis
author: Lai Man Tang(Nancy)
email: [email protected]
'''
from newsdb import popular_articles, popular_authors, request_error
import datetime
def main():
op = open('newsreport' + '.txt', 'w')
op.write('\nNew Report -- ' + str(datetime.datetime.now()))
op.write('\n\nthe most popular three articles of all time\n\n')
result = popular_articles()
count = 1
for text in result:
s = str(count) + ': ' + text[0] + '---' + str(text[1]) + " views\n"
op.write(s)
count += 1
op.write('\n\nthe most popular article authors of all time\n\n')
result = popular_authors()
count = 1
for text in result:
s = str(count) + ': ' + text[0] + '---' + str(text[1]) + " views\n"
op.write(s)
count += 1
op.write('\n\nthe day that has more than 1% of requests lead to errors\n')
result = request_error()
count = 1
for text in result:
p2 = float(text[2])
p1 = p2/float(text[1])*100
if p1 > 1:
s = str(count) + ': ' + str(text[0])
s += '---' + " " + str(p1) + "%\n\n"
op.write(s)
count += 1
op.close()
if __name__ == '__main__':
main()