summaryrefslogtreecommitdiff
path: root/stock.py
diff options
context:
space:
mode:
Diffstat (limited to 'stock.py')
-rw-r--r--stock.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/stock.py b/stock.py
new file mode 100644
index 0000000..410e16a
--- /dev/null
+++ b/stock.py
@@ -0,0 +1,59 @@
+import sys, time
+import ezodf
+import pickle
+from collections import OrderedDict
+
+def parse_file(f, sheet, keyno, fields, skip_first=1, skip_last=0):
+ l = []
+ try: # Read EagleDbDict or create it if not present
+ ods = ezodf.opendoc(f)
+ sheet = ods.sheets[sheet]
+ for index in range(skip_first, sheet.nrows()-skip_last):
+ new = [sheet[index, keyno].value]
+ new.extend(sheet[index, i].value for i in fields)
+ l.append(new)
+ #print(key, Data)
+ except IOError as err:
+ print('No stockFile Named:', f)
+ return None
+ return l
+
+#Get Avencall stock
+Stock = parse_file('../AvenCallHardwareStock.ods', 'Work', 0, (2,4))
+Quote = parse_file('/home/massoud/Projets/XiVO/Software/proto_pcbs/pcb_xioh/Ver5/EgV6-XIOHV5/BoM/Commandes/Digikey/XIOHv5-Digikey-Order-quote7081688.ods',
+ 'dk', 0, (3,5), skip_first=0, skip_last=2)
+EagleBom = parse_file('../EagleBom.ods','BomProcess', 0, (6,5))
+
+#disp_struct(Stock)
+#disp_struct(Quote)
+
+
+def join(a, b, fa, fb):
+ return [ (j, k) for j in a for k in b if j[fa] == k[fb] ]
+
+def disp_struct(s):
+ print(len(s), s)
+
+disp_struct(EagleBom)
+
+def disp_struct_filter(sname, filter):
+ print(list(k for k in sname if k[2]!= filter))
+
+disp_struct_filter(EagleBom, 'digikey')
+#disp_struct_filter(EagleBom, 'Farnell')
+
+join_eagle_quote = list((j,k) for (j,k) in join(EagleBom,Quote,1,0) if k[2])
+#disp_struct(join_eagle_quote)
+
+def write_result(fname, sheetname, tbl):
+ ods = ezodf.opendoc(fname)
+ for sheet in ods.sheets:
+ pass
+# print(sheet.name)
+ sheet = ods.sheets[sheetname]
+ sheet.insert_rows(0,len(tbl))
+ for i in range(len(tbl)):
+ sheet[i,0].set_value(tbl[i][0][1])
+ ods.save()
+
+write_result('/home/massoud/Projets/XiVO/Software/proto_pcbs/pcb_xioh/Ver5/EgV6-XIOHV5/BoM/Commandes/Digikey/XIOHv5-Digikey-Order-quote7081688.ods','order',join_eagle_quote)