def InsertActivities(self, path): text = open(path).readlines() for line in text: line.replace(' ', '') ## remove all whitespaces line = line.split(',') product_id = int(line[0]) units_quantity = int(line[1]) supplier_id = int(line[2]) date_string = line[3] cur = self._conn.cursor() q = self.products.find(product_id) if units_quantity > 0: ## suply a = DTO.Activity(product_id, units_quantity, supplier_id, date_string) self.activities.insert(a) self.products.update_quantity(units_quantity, product_id) elif int(q) + units_quantity >= 0: ## sell legal a = DTO.Activity(product_id, units_quantity, supplier_id, date_string) self.activities.insert(a) self.products.update_quantity(units_quantity, product_id)
def main(actions_file): with open(actions_file, 'r') as f: for line in f.readlines(): args = line.split(',') args = [arg.strip() for arg in args] activity = DTO.Activity(*args) curr_quantity = repo.products.get_quantity(activity.product_id) new_quantity = curr_quantity + int(activity.quantity) if new_quantity >= 0: repo.activities.insert(activity) repo.products.update(activity.product_id, activity.quantity) printdb.main()