Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
23 changes: 23 additions & 0 deletions logger.py
Original file line number Diff line number Diff line change
@@ -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')

40 changes: 40 additions & 0 deletions viewer.py
Original file line number Diff line number Diff line change
@@ -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()