From c2942779b318df430c17ccddbb1528d170b42d10 Mon Sep 17 00:00:00 2001 From: Josephine Wanjiku Date: Wed, 23 May 2018 07:04:32 -0400 Subject: [PATCH] initial commit --- .DS_Store | Bin 0 -> 6148 bytes logger.py | 23 +++++++++++++++++++++++ viewer.py | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 .DS_Store create mode 100644 logger.py create mode 100644 viewer.py diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..bebf8c3c2bd18b5bedc2413bc48deed39d2861d9 GIT binary patch literal 6148 zcmeHK&2G~`5S~p_u!)3>)I*Vau*88&R0X-v0~a?Wm5@N7x}paPsa>1KlJQ2i(+EY8 zEFORdfGa=ZHGqfU%sX&~Z-0my3a3g4RXfq{H#<8s&VFm{dWeX1$MFp!hlngRfejno zA4JTHc1jxBvJ7M*$K8w{Mj4MV772~~{|tz|Yf?;{4ypWY|88UM*$*jlA#=ZIQjYXK ze~(64T2`ITSJqf+E?>B4*_T>&>vGF}5)AnysKRPocEe)etOaSDL}9U)#?^2)$@^Jy zoa7IRdtsFnkA?Ft=NTN79!8JSWHNA8?(n<{(>y6;K9ysCFU?~<>GE+Nm(pJ+m-@r7 z8X}K%%|EE+AGa-g;H*xko_DkDdK=!X?M^p0J8gHvyEU8HmUZ>|_RiDs%U7@8ynXln z!>7+OiWpvMDOWW9f-g|!WE=-Yp7Hz$HsNnm1~QNEOQ@iA8qteITG=;v?Vq64rXA|j z7WL>paGjo0ycj_r5pi-OFf?KqFbo(5&cc8`-mKPHl9*V-fMMWVG9b%CFTTd-c+_f&+ s0h$ouS1X){K#^B5e8p9~iY5hiS13SVW33Pti1`qZG?>mX@J|`|333{SMgRZ+ literal 0 HcmV?d00001 diff --git a/logger.py b/logger.py new file mode 100644 index 0000000..3bc219d --- /dev/null +++ b/logger.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue May 22 + +@author: Josephine Nyoike +""" +import random +from datetime import datetime, timedelta +import sys + +def date_generator(): + '''generate a random date''' + begin = datetime(2017, 1, 1, 00, 00, 00) + end = begin + timedelta(days=365 * 2) + return begin + (end - begin) * random.random() + +for i in range (1000): + '''print exactly 1000 lines''' + date = date_generator() + date2 = date.strftime("%d/%m/%Y") + sys.stdout.write(date2 + '\n') + \ No newline at end of file diff --git a/viewer.py b/viewer.py new file mode 100644 index 0000000..8a4833a --- /dev/null +++ b/viewer.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue May 22 + +@author: Josephine Nyoike +""" +import datetime +import sys +def check_date_format(date): + '''check that the date provided is in the correct format, else throw an error''' + try: + datetime.datetime.strptime(date, '%d/%m/%Y') + except ValueError: + raise ValueError("Malformed output") +def count_months(months): + '''count the months used in a line and print their percentages''' + unique_months = [] + for month in months: + if month not in unique_months: + unique_months.append(month) + for month1 in unique_months: + c = months.count(month1) + percentage = c/len(months) * 100 + string_percentage = month1 + ': '+ str(percentage) + '%' + print(string_percentage) +def main(): + + lines = sys.stdin.readlines() + months = [] + for date in lines: + check_date_format(date) + if date.year == 2018 and date.day in range(0, 15): + print(date) + month_name = date.strftime("%B") + months.append(month_name) + + months.sort() + count_months(months) +main() \ No newline at end of file