harvest_issues/generate_issues.py
Louis Elkner-Alfaro cfcd09a567 Init commit
2023-10-03 12:15:36 -07:00

56 lines
1.6 KiB
Python

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()