-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDebugging and Solving Software Problems
More file actions
60 lines (46 loc) · 1.82 KB
/
Debugging and Solving Software Problems
File metadata and controls
60 lines (46 loc) · 1.82 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
import csv
import datetime
import requests
FILE_URL="http://marga.com.ar/employees-with-date.csv"
def get_start_date():
"""Interactively get the start date to query for."""
print()
print('Getting the first start date to query for.')
print()
print('The date must be greater than Jan 1st, 2018')
year = int(input('Enter a value for the year: '))
month = int(input('Enter a value for the month: '))
day = int(input('Enter a value for the day: '))
print()
return datetime.datetime(year, month, day)
def get_file_lines(url):
"""Returns the lines contained in the file at the given URL"""
# Download the file over the internet
response = requests.get(url, stream=True)
# Decode all lines into strings
lines = []
for line in response.iter_lines():
lines.append(line.decode("UTF-8"))
return lines
def get_same_or_newer(start_date):
"""Returns the employees that started on the given date, or the closest one."""
data = get_file_lines(FILE_URL)
reader = csv.reader(data[1:])
# We want all employees that started at the same date or the closest newer
# date. To calculate that, we go through all the data and find the
# employees that started on the smallest date that's equal or bigger than
# the given start date.
min_date = datetime.datetime.today()
min_date_employees = []
for row in sortedlist:
row_date = datetime.datetime.strptime(row[3], '%Y-%m-%d')
# If this date is smaller than the one we're looking for,
# we skip this row
if row_date >= start_date:
print("Started on {} : {} {}".format(row_date.strftime("%b %d, %Y"),row[0], row[1]))
def sortedlist():
start_date = get_start_date()
sortedlist(start_date)
if __name__ == "sortedlist_":
sortedlist()