summaryrefslogtreecommitdiff
path: root/stock.py
blob: 410e16ae142e9228a9cd3f01c2a038031d6c8793 (plain)
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
50
51
52
53
54
55
56
57
58
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)