Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How can I make this code faster?

+2 votes
asked Mar 28, 2020 by Joe (140 points)

import csv

import datetime

import requests


def get_start_date():

    """Interactively get the start date to query for."""


    print('Getting the first start date to query for.')


    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: '))


    return datetime.datetime(year, month, day)

def get_file_lines(url):


    # Download the file over the internet

    response = requests.get(url, stream=True)

    lines = []

    for line in response.iter_lines():


    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:])

    min_date = datetime.datetime.today()

    min_date_employees = []

    for row in reader:

        row_date = datetime.datetime.strptime(row[3], '%Y-%m-%d')

        if row_date < start_date:


        if row_date < min_date:

            min_date = row_date

            min_date_employees = []

        if row_date == min_date:

            min_date_employees.append("{} {}".format(row[0], row[1]))

    return min_date, min_date_employees

def list_newer(start_date):

    while start_date < datetime.datetime.today():

        start_date, employees = get_same_or_newer(start_date)

        print("Started on {}: {}".format(start_date.strftime("%b %d, %Y"), employees))

        start_date = start_date + datetime.timedelta(days=1)

def main():

    start_date = get_start_date()


if __name__ == "__main__":


1 Answer

0 votes
answered Mar 29, 2020 by AFFAQ SAJID (140 points)
very important point for the students to leran that
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.