-
Notifications
You must be signed in to change notification settings - Fork 0
/
STID_reader.py
49 lines (40 loc) · 1.56 KB
/
STID_reader.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""Read excel database."""
import os
import json
import pandas as pd
GB = "GEN11_MASTER_TCP_GB_NEW.xlsx"
EXCEL_DIR = r'Z:\Engineering\01.OnStar\11.Flashing\01.Reflash\Excel Database'
def main():
"""Main."""
if not os.path.exists("reader_output"):
os.mkdir("reader_output")
df = pd.read_excel(os.path.join(EXCEL_DIR, GB), sheet_name=None, dtype=str)
unused = []
used = []
unused_STIDs = {}
used_STIDs = {}
for sheet_name in df.keys():
if sheet_name[-1] == 'B':
continue
for _, row in df[sheet_name].iterrows():
if not pd.isnull(row['STID']):
if pd.isnull(row['#']) and pd.isnull(row['LG Contact']) and \
pd.isnull(row['CCM SW']) and pd.isnull(row['CCM HW']) and \
pd.isnull(row['VIM SW']) and pd.isnull(row['VIM HW']):
unused.append(row)
unused_STIDs[row['STID']] = 1
else:
used.append(row)
used_STIDs[row['STID']] = 1
# Output json files
with open('reader_output/unused_GB.txt', 'w') as file:
json.dump(unused_STIDs, file)
with open('reader_output/used_GB.txt', 'w') as file:
json.dump(used_STIDs, file)
# Sample Output on Excel Files
df_unused = pd.DataFrame(unused, columns=df['MY20Gen11CN_GB'].columns)
df_unused.to_excel("reader_output/unused_GB.xlsx")
df_used = pd.DataFrame(used, columns=df['MY20Gen11CN_GB'].columns)
df_used.to_excel("reader_output/used_GB.xlsx")
if __name__ == "__main__":
main()