From cfcd09a567eac14fa3ea036f74de39895153491d Mon Sep 17 00:00:00 2001 From: Louis Elkner-Alfaro Date: Tue, 3 Oct 2023 12:15:36 -0700 Subject: [PATCH] Init commit --- generate_issues.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 generate_issues.py diff --git a/generate_issues.py b/generate_issues.py new file mode 100644 index 0000000..05f9479 --- /dev/null +++ b/generate_issues.py @@ -0,0 +1,56 @@ +import os +import csv +import re + +# {'harvest_project': ('owner', 'repo')} +projects = { + 'harvest_project': (owner, repo), +} + +def test_parse_notes_section(): + if (parse_notes_section('Resolved Issue #4, #5 and Issue 6') == ['Issue #4', '#5', 'Issue 6']): + print("test parse_notes_section passed") + else: + print("Test parse_notes_section failed") + + +def parse_notes_section(notes): + print("NOTES: ", notes) + regex_pattern = r"[Ii]ssue\s*(?:#)?\d+|#\d+" + matches = re.findall(regex_pattern, notes) + if matches: + print("MATCHES: ", matches) + return matches + + + +def parse_harvest_csv(file=None): + if file is None: + file = input('Enter harvest report: ') + print(file) + + if os.path.exists(file): + print('Beginning parsing for issues') + + with open(file, 'r') as f: + csv_reader = csv.DictReader(f) + rows = list(csv_reader) + original_fieldnames = csv_reader.fieldnames + + issue_fields = ['First Issue', 'Second Issue', 'Third Issue'] + modified_fieldnames = original_fieldnames + issue_fields + + with open('modified_csv.csv', 'w', newline='') as csvfile: + writer = csv.DictWriter(csvfile, fieldnames = modified_fieldnames) + writer.writeheader() + for row in rows: + issues = parse_notes_section(row['Notes']) + issues_dict = dict(zip(issue_fields, issues)) + writer.writerow(issues_dict) + + +def test_program(): + parse_harvest_csv("louis_harvest_time_report_from2023-10-01to2023-10-07.csv") + +test_parse_notes_section() +test_program()