diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..bebf8c3 Binary files /dev/null and b/.DS_Store differ 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