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
24 changes: 24 additions & 0 deletions Codes/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'''
Infra Internship Code Challenge

Task 1

This script writes 1000 lines of text to standard output. Each line of text is a date in the form dd/MM/YYYY
'''
import random
import sys


def randomize():
day = str(random.randint(1, 30))
month = str(random.randint(1, 12))
year = random.randint(17, 18)
return day.zfill(2) + '/' + month.zfill(2) + '/20' + str(year) + '\n'


def output():
for x in range(0, 1000):
print randomize()


output()
9 changes: 9 additions & 0 deletions Codes/pipe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'''
Infra Internship Code Challenge

Task 3

This script launches the logger program and pipes its output to the viewer program.
'''
import os
os.system("python logger.py|python viewer.py")
54 changes: 54 additions & 0 deletions Codes/viewer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'''
Infra Internship Code Challenge

Task 2

This program reads lines of text from the standard input,counts how many times a month appears and displays dates from 0-14th of 2018
'''
import sys
month_count = [0] * 12


def format(date):
#Displays Malformed Input whenever the input isn't in the format DD/MM/YYYY
if int(date[:2]) > 0 and int(date[:2]) < 31:
if int(date[3:5]) > 0 and int(date[3:5]) < 13:
if (len(date[6:-1]) == 4):
return 0
else:
print 'Malformed Input'


def read(date):
#increments the month_count for month X whenever it appears
month = int(date[3:5]) - 1
month_count[month] = month_count[month] + 1


def count():
#prints the logged months with the percentage that month appears
month = [
'January', 'February', 'March', 'April', 'May', 'June', 'July',
'August', 'September', 'October', 'November', 'December'
]
print "_________________________________________"
for x in month:
perc = month_count[month.index(x)] / 10.0
print x + ': ' + str(perc) + '%'
print "_________________________________________"


def fourteenth(date):
#Print lines from 0-14th of 2018
if int(date[:2]) > 0 and int(date[:2]) < 14:
if int(date[-3:-1]) == 18:
print date[:-1]


for date in sys.stdin:
if date.strip():
format(date)
read(date)
fourteenth(date)

count()