Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def updatepodb(pofile):
- """parse purchase order data into database"""
- #regex (?:[\w ]{6}? (\w{3,10}).*?|\s*?)-(\d+).{14}.*?(\d+).*?([a-zA-Z ]*)$
- rawpo = open(pofile,'r').read()
- sku = str()
- sliced = rawpo.split('\n')
- lineitems = []
- for line in sliced:
- """search for the data"""
- match = re.search(r'(?:[\w ]{6}? (\w{3,10}).*?|\s*?)-(\d+).{14}.*?(\d+).*?([a-zA-Z ]*)$',line)
- if not match:
- continue
- if match.group(1):
- sku = match.group(1)
- po_num = match.group(2)
- qty = match.group(3)
- status = match.group(4).strip()
- vendor = re.match(r'^([A-Za-z]+)',sku).group(1)
- print "VENDOR: %s PO #: %s SKU: %s QTY: %s STATUS: %s" % (vendor, po_num, sku, qty, status)
- lineitems.append((po_num, vendor, sku, qty, status))
- #print lineitems
- dbclear = 1
- connection = sqlite3.connect(podatabase)
- with connection:
- cursor = connection.cursor()
- if dbclear == 1:
- cursor.execute('DELETE from onorder')
- dbclear = 0
- cursor.executemany('insert into onorder (PONUM,VENDOR,SKU,SKUQTY,STATUS) values (?,?,?,?,?)', lineitems)
Add Comment
Please, Sign In to add comment