-
-
Notifications
You must be signed in to change notification settings - Fork 132
/
extract_cnae_cnpj.py
33 lines (24 loc) · 903 Bytes
/
extract_cnae_cnpj.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
import argparse
import csv
import rows
from tqdm import tqdm
def main():
parser = argparse.ArgumentParser()
parser.add_argument("empresa_csv_filename")
parser.add_argument("cnae_secundaria_csv_filename")
parser.add_argument("output_csv_filename")
args = parser.parse_args()
writer = rows.utils.CsvLazyDictWriter(args.output_csv_filename)
fobj = rows.utils.open_compressed(args.empresa_csv_filename)
reader = csv.DictReader(fobj)
for row in tqdm(reader):
writer.writerow({"cnpj": row["cnpj"], "cnae": row["cnae_fiscal"], "primaria": "t"})
fobj.close()
fobj = rows.utils.open_compressed(args.cnae_secundaria_csv_filename)
reader = csv.DictReader(fobj)
for row in tqdm(reader):
writer.writerow({"cnpj": row["cnpj"], "cnae": row["cnae"], "primaria": "f"})
fobj.close()
writer.close()
if __name__ == "__main__":
main()