class ExtractWoocommerceProducts(ExtractWoocommerceDataToCSV): filename = 'products.csv' query = load_content_from_file('./sql/products.sql') def requires(self): yield CreateProductCategoryTable(self.date) yield CreateProductLastOrderTable(self.date)
def inner_run(self, connection, cursor): if self.query and self.query != '_load_from_input_': sqlFileContent = self.query else: sqlFileContent = load_content_from_file(self.input().path) # all SQL commands (split on ';\n' (newline)) sqlCommands = re.split(";\n", sqlFileContent) # Execute every command from the input file for command in sqlCommands: if command.isspace(): continue # This will skip and report errors # For example, if the tables do not yet exist, this will skip over # the DROP TABLE commands try: cursor.execute(command) except OperationalError, msg: print "Command skipped: ", msg except ProgrammingError, msg: raise Exception( "ProgrammingError '{}' while executing following sql command: {}" .format(msg, command))
class ExtractWoocommerceStock(ExtractWoocommerceDataToCSV): filename = 'stock.csv' query = load_content_from_file('./sql/stock.sql') def write_row(self, output, row): l = list(row) l.append(str(self.date)) output.write(*tuple(l))
class ExtractCampaignTrackings(ExtractWoocommerceDataToCSV): filename = 'campaign_trackings.csv' query = load_content_from_file('./sql/campaign_trackings.sql')
class ExtractWoocommerceOrders(ExtractWoocommerceDataToCSV): filename = 'orders.csv' query = load_content_from_file('./sql/orders.sql')
class ExtractWoocommerceAddresses(ExtractWoocommerceDataToCSV): filename = 'addresses.csv' query = load_content_from_file('./sql/addresses.sql')
class CreateProductLastOrderTable(MySQLTransformStepAfterImport): table = 'products__last_order_date' query = load_content_from_file('./sql/products__last_order_date.sql')
class CreateProductCategoryTable(MySQLTransformStepAfterImport): table = 'category_tree' query = load_content_from_file('./sql/products__category_tree.sql')