Commit f36bf47e authored by Dax Mickelson's avatar Dax Mickelson

Improve looping and use csv DictReader.

parent 548c9397
......@@ -12,28 +12,25 @@ VOICEMAIL_PASSWORD = '12345'
def write_csv_file(extensions) -> None:
with open(OUTPUT_CSV_FILE, 'w', newline='') as f:
writer = csv.DictWriter(f, fieldnames=extensions[0].HEADER)
writer = csv.DictWriter(f, fieldnames=Extension.HEADER)
writer.writeheader()
writer.writerows(extension.to_dict for extension in extensions)
def main() -> None:
# Create a "dumping place" where all the built Extension objects will be stored.
extensions = []
# Load input csv file
fieldnames = ('Extension', 'First Name', 'Last Name')
with open(INPUT_CSV_FILE, 'r') as f:
raw_csv_input = csv.reader(f, delimiter=',', quotechar='"')
rows = []
raw_csv_input = csv.DictReader(f, quotechar='"', fieldnames=fieldnames)
# Use the collected information to build each extension
for row in raw_csv_input:
rows.append(row)
# Use the collected information to build each extension
extensions = []
for count, row in enumerate(rows):
# Skip blank rows, or rather, rows with no data in the first field.
if row[0] and count != 0:
print(f'Loading {row} from input file.')
extension = row[0]
name = f'{row[1].strip().capitalize()} {row[2].strip().capitalize()}'
email = f"{row[1].strip().lower()}.{row[2].strip().lower()}@{EMAIL_DOMAIN}"
# Skip blank rows, or rather, rows with no data in the first field.
extension = row['Extension']
name = f"{row['First Name'].strip().capitalize()} {row['Last Name'].strip().capitalize()}"
email = f"{row['First Name'].strip().lower()}.{row['Last Name'].strip().lower()}@{EMAIL_DOMAIN}"
# Now that the pertinent information has been formatted, build the extension class
data_vars = {'name': name,
......
......@@ -4,3 +4,13 @@ This package is designed to assist in formatting the CSV file.
"""
from .Extension import *
def __authorship__():
"""
***********************************************************************************************************************
This python module was created by Dax Mickelson along with LOTs of help from my friend and colleague Dmitry Figol.
***********************************************************************************************************************
"""
__authorship__()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment