Skip to content

Instantly share code, notes, and snippets.

@lindsm
Created December 13, 2015 22:50
Show Gist options
  • Save lindsm/c4c7a9aa507cf0b95566 to your computer and use it in GitHub Desktop.
Save lindsm/c4c7a9aa507cf0b95566 to your computer and use it in GitHub Desktop.
class Excel_Data():
def __init__(self, path):
self.name = path
self.book = xlrd.open_workbook(self.name)
self.sheet_names = self.book.sheet_names()
self.first_sheet = self.book.sheet_by_index(0)
self.xls_type = self.check_xls_type()
if self.xls_type == 'DIAMOND':
self.sales = self.build_diamond(self.first_sheet, self.xls_type)
self.products = self.get_products(self.sales)
def check_xls_type(self):
'''
Check what distributor a given spreadsheet is from and return it.
'''
cell = self.book.sheet_by_index(0).cell(0, 0).value
if 'DIAMOND COMIC' in cell:
return 'DIAMOND'
def get_products(self, sales_rows):
'''
Given a list of sales_rows, return a list of the ISBN's or ITEM#'s
'''
products = []
for sale in sales_rows:
if sale['isbn']:
prodcuts.append(sale['isbn'])
elif sale['item']:
prodcuts.append(sale['item'])
else:
print("NO NUMBER FOUND for {0}".format(sale))
return products
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment