Guest User

Untitled

a guest
Sep 26th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. def updatepodb(pofile):
  2. """parse purchase order data into database"""
  3. #regex (?:[\w ]{6}? (\w{3,10}).*?|\s*?)-(\d+).{14}.*?(\d+).*?([a-zA-Z ]*)$
  4. rawpo = open(pofile,'r').read()
  5. sku = str()
  6. sliced = rawpo.split('\n')
  7.  
  8. lineitems = []
  9.  
  10. for line in sliced:
  11. """search for the data"""
  12. match = re.search(r'(?:[\w ]{6}? (\w{3,10}).*?|\s*?)-(\d+).{14}.*?(\d+).*?([a-zA-Z ]*)$',line)
  13.  
  14. if not match:
  15. continue
  16. if match.group(1):
  17. sku = match.group(1)
  18.  
  19. po_num = match.group(2)
  20. qty = match.group(3)
  21. status = match.group(4).strip()
  22. vendor = re.match(r'^([A-Za-z]+)',sku).group(1)
  23. print "VENDOR: %s PO #: %s SKU: %s QTY: %s STATUS: %s" % (vendor, po_num, sku, qty, status)
  24.  
  25. lineitems.append((po_num, vendor, sku, qty, status))
  26.  
  27. #print lineitems
  28. dbclear = 1
  29. connection = sqlite3.connect(podatabase)
  30. with connection:
  31. cursor = connection.cursor()
  32. if dbclear == 1:
  33. cursor.execute('DELETE from onorder')
  34. dbclear = 0
  35. cursor.executemany('insert into onorder (PONUM,VENDOR,SKU,SKUQTY,STATUS) values (?,?,?,?,?)', lineitems)
Add Comment
Please, Sign In to add comment