-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathldproducts.py
executable file
·36 lines (27 loc) · 1.01 KB
/
ldproducts.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
#!/usr/local/bin/python3
#
# load in products
from eaidb import EAIdb
import csv
import re, sys
################################################################
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description='Load test descriptions')
parser.add_argument('-d', action='store_true', help="Debug");
parser.add_argument('products', type=str, help="CSV file of products");
args = parser.parse_args();
db = EAIdb(None, debug=args.d)
flds = ('pid', 'name', 'vendor', 'email', 'types')
with open(args.products, "r", newline='') as f:
crd = csv.reader(f,delimiter=';')
first = True
for l in crd:
if first: # skip headers on the first line
first = False
continue
proddict = dict(zip(flds, l)) # seven fields into
if args.d:
print(proddict)
r = db.addproduct(proddict, update=True)
print(r, proddict['name'])