-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput_functions.py
29 lines (23 loc) · 1016 Bytes
/
output_functions.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
import pandas as pd
import json
def convert_to_csv(dctlist, filename):
df = pd.DataFrame(dctlist)
column_order = df.columns[:9].tolist() + sorted(df.columns[9:].tolist())
df_sorted = df[column_order]
df_sorted.to_csv(f'.\\output\\{filename}.csv', index=False)
df_sorted.to_excel(f'.\\output\\{filename}.xlsx', index=False)
def log_appender(dctlist):
try:
with open('.\\log\\log.json', 'r') as in_file:
logdata = json.load(in_file)
except FileNotFoundError:
logdata = []
logdata.extend(dctlist)
undupl_logdata = list({dct['2GIS URL']: dct for dct in logdata}.values())
with open('.\\log\\log.json', "w") as file:
json.dump(undupl_logdata, file, ensure_ascii=False)
df = pd.DataFrame(undupl_logdata)
column_order = df.columns[:9].tolist() + sorted(df.columns[9:].tolist())
df_sorted = df[column_order]
df_sorted.to_csv(f'.\\merged\\merged.csv', index=False)
df_sorted.to_excel(f'.\\merged\\merged.xlsx', index=False)