Commit f7bb91b3 authored by Dax Mickelson's avatar Dax Mickelson

Initial commit

parent f8e917b8
.env
.idea/*
__pycache__
*.csv
*.xls
*.xlsx
#! /usr/bin/env python3
import csv
from freepbx_bulk_handler import Extension
# GLOBALS
INPUT_CSV_FILE = 'extensions_to_create.csv'
OUTPUT_CSV_FILE = 'extensions_to_import.csv'
EMAIL_DOMAIN = 'example.com'
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.writeheader()
writer.writerows(extension.to_dict for extension in extensions)
def main() -> None:
# Load input csv file
with open(INPUT_CSV_FILE, 'r') as f:
raw_csv_input = csv.reader(f, delimiter=',', quotechar='"')
rows = []
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}"
# Now that the pertinent information has been formatted, build the extension class
data_vars = {'name': name,
'extension': extension,
'voicemail_vmpwd': VOICEMAIL_PASSWORD,
'voicemail_email': email}
extensions.append(Extension(**data_vars))
# Write finished extensions to a csv file.
write_csv_file(extensions)
if __name__ == '__main__':
main()
Extension,First Name,Last Name
101,Anoni,Mouse
102,Warren,Piece
103,TsuDoh,Nimh
This diff is collapsed.
"""
FreePBX Bulk Handler uses CSV files for importation.
This package is designed to assist in formatting the CSV file.
"""
from .Extension import *
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