-
Notifications
You must be signed in to change notification settings - Fork 2
/
csv_writer.py
32 lines (27 loc) · 1.35 KB
/
csv_writer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# pylint: disable=line-too-long
"""
Write source, receive, high volume receiving site CSV files
"""
import csv
import os
import logging
import constant
LOGLEVEL = os.getenv('LOGLEVEL')
logging.basicConfig(level=LOGLEVEL, format='%(asctime)s [%(levelname)s] %(message)s')
def site_csv_writer(source_sites, receiving_sites, hv_sites):
"""Create source, receive, high volume receiving CSV file"""
logging.info('Creating soil source site CSV...')
with open(constant.SOURCE_CSV_FILE, 'w', encoding='UTF8', newline='') as source_file:
writer = csv.DictWriter(source_file, fieldnames=constant.SOURCE_SITE_HEADERS, extrasaction='ignore')
writer.writeheader()
writer.writerows(source_sites)
logging.info('Creating soil receiving site CSV...')
with open(constant.RECEIVE_CSV_FILE, 'w', encoding='UTF8', newline='') as receive_file:
writer = csv.DictWriter(receive_file, fieldnames=constant.RECEIVING_SITE_HEADERS, extrasaction='ignore')
writer.writeheader()
writer.writerows(receiving_sites)
logging.info('Creating soil high volume site CSV...')
with open(constant.HIGH_VOLUME_CSV_FILE, 'w', encoding='UTF8', newline='') as high_volume_file:
writer = csv.DictWriter(high_volume_file, fieldnames=constant.HV_SITE_HEADERS, extrasaction='ignore')
writer.writeheader()
writer.writerows(hv_sites)