diff --git a/task-02/completed.md b/task-02/completed.md index bca9187..b46ac7f 100644 --- a/task-02/completed.md +++ b/task-02/completed.md @@ -1,2 +1,3 @@ ## Those who have completed this task: +hector-mr diff --git a/task-03/get_top_names.py b/task-03/get_top_names.py index 4535204..4f33ff7 100644 --- a/task-03/get_top_names.py +++ b/task-03/get_top_names.py @@ -1,25 +1,62 @@ -""" -get_top_names.py -For astrophg/learning-by-doing: Task 3 -https://github.com/astropgh/learning-by-doing/tree/master/task-03 -""" +#""" +#get_top_names.py +#For astrophg/learning-by-doing: Task 3 +#https://github.com/astropgh/learning-by-doing/tree/master/task-03 +#""" -def extract_data_lines(filename, start_text, end_text): +def extract_data_lines(filename, start_text, end_text, include_start = False, include_end = False): """ open `filename`, and yield the lines between the line that contains `start_text` and the line that contains `end_text` """ - # fill in code as needed + + # Needed to record the text in between + parsing = False + + # use `yield line` to return desired lines but keep the function going with open(filename) as fh: + for line in fh: - # fill in code as needed - # use `yield line` to return desired lines but keep the function going + + ###################################################################### + + if start_text in line: + + parsing = True + + if not include_start: + + continue + + ###################################################################### + + elif end_text in line: + + if include_end: + + #parsing = True + yield line + break + + else: + + parsing = False + + ###################################################################### + + + if parsing: # Do stuff with the data + + yield line + if __name__ == '__main__': filename = 'top5names.html' start_text = '2017' end_text = '' + - for line in extract_data_lines(filename, start_text, end_text): - print(line) + for line in extract_data_lines(filename, start_text, end_text, include_start = False, include_end = False): + + print(line) \ No newline at end of file