def update_product_inventory(transaction_executor, scentity_id, product_id, product_instances, case_ids, pallete_ids, container_ids, delivered_product_quantity): inventory_table_name = inventory_table_already_exist( transaction_executor, scentity_id) if inventory_table_name: pass else: inventory_table_name = "INVENTORY" + scentity_id create_table(transaction_executor, inventory_table_name) create_index(transaction_executor, inventory_table_name, "ProductId") if product_exist_in_inventory(transaction_executor, inventory_table_name, product_id): update_current_product_inventory(transaction_executor, inventory_table_name, product_id, product_instances, case_ids, pallete_ids, container_ids, delivered_product_quantity) # logger.info("inventory was updated") ## update the inventory by amount and insert the container_id, pallete,cases else: inventory_id = generate_new_product_inventory( transaction_executor, inventory_table_name, product_id, product_instances, case_ids, pallete_ids, container_ids, delivered_product_quantity)
def switch(type, arguments): if type == "model": create_model(arguments), elif type == "table": create_table(arguments[0]) elif type == "route": create_route(arguments[0]) else: raise Exception( "%s is not a valid argument please enter model or table" % (type))
def handler(event, context): print("Reading data") get_data(path='/tmp') print("Parsing PDF") create_table(path='/tmp', verbose=False) print("Processing output") df_json = convert_to_db(path='/tmp') print("Saving to S3") _save_to_s3('/tmp') return {"message": "Success", "firstRecord": df_json[0]}
def build_db(files): ''' Builds/updates database using the files collected Inputs: files (lst): list of filenames to add to database Returns: None, updates SQL database school_access.sqlite3 ''' print("Creating tables in the sqlite3 database.") connection = sqlite3.connect('school_access.sqlite3') c = connection.cursor() for filename in files: parsed_filename = re.search(r'((?:[\w-]+))\.[\w-]+', filename).group(1) print(f"Updating {parsed_filename} in SQL database...") query1 = "DROP TABLE IF EXISTS " + parsed_filename c.execute(query1) unwanted_cols = FILENAMES.get(filename, None) create_table(DATA_DIR + filename, unwanted_cols) print("Table(s) updated")
def import_csv(TABLE_NAME,DESCRIPTION,URL,REPLACE_EXISTING,ENCODING,IS_CLEAN): print ">>> Retrieving CSV." if URL.find("http") == 0: r = requests.get(URL) if r.status_code == requests.codes.ok: print ">>> CSV successfully retrieved." text = r.text else: print ">>> Failed to get CSV. Returned status %i" % r.status_code print ">>> Error message: %s" % r.text sys.exit() else: try: if URL.find("~") == 0: URL = os.path.expanduser(URL) f = codecs.open(URL,"rt",encoding=ENCODING) text = f.read() print ">>> File read successfully." except Exception as e: print ">>> Could not read file." print ">>> Error message: %s" % e sys.exit() table = cc.clean(text) header = table[0] body = table[1] token = cu.create_upload(body) status_link = ct.create_table(TABLE_NAME,DESCRIPTION,token,header,REPLACE_EXISTING,IS_CLEAN) polling_response = pis.poll_import_status(status_link) response_status = polling_response['state'] if response_status == "failed": print polling_response response = polling_response['error_message'] print ">>> Table creation failed." print ">>> Error message: %s" % response else: response = pis.lookup_table(TABLE_NAME) js = json.loads(response.text) web_url = js['_links']['web']['href'] print ">>> Import successful." print ">>> Table location: %s" % web_url
new_table = """ CREATE TABLE IF NOT EXISTS {tb_name} ( my_index INT(5) NOT NULL, id INT(10), title VARCHAR(200), chi_title VARCHAR(200), raters INT(10), average_rate FLOAT(4, 1), PRIMARY KEY(my_index) );""".format(tb_name = table_name) #Drop a table drop_table(my_host, user_name, my_password, db_name, delete_table) #Create a new table create_table(my_host, user_name, my_password, db_name, new_table) #Main Program for page in range(pages): #Get ID number = page * num_each_page ID_list = get_ID(number, tag_name, pattern_text, headers, id_url) time.sleep(3) print('Pages Cruising Procedure: '\ '{:.2%}'.format(page/pages)) for single_id in ID_list: my_index += 1 #Get information of id try:
def main(): ct.create_table() cmd_line()
def add_file_to_db(self): filename = askopenfilename() if not filename == "": create_table.create_table(filename, self.dbname)
return jsonify(getBestFit(student_score, exam_type, max_expense)) ## This route takes in the prefered size and/or minimum addimission rate for a college ## do the filtering in the SQL table, and return the opeid and college names that satisfy the ## requirement @app.route("/search/advanced") def advanced_search(): data = request.json searchFilter = {} if "size" in data: searchFilter["size"] = data["size"] if "adr" in data: searchFilter["adr"] = data["adr"] return jsonify(search(searchFilter)) ## This route takes in what the users type in searching bar, make searches ## on the official site of that college, and return the data in this format: ## [{"headline": "xxxx", "link": "https://....."}, {"headline":"", "link": "..."}] @app.route("/searchInfo/<int:opeid>") def searchForInfo(): return null ## Add signup and get user resource api.add_resource(UserRegister, "/signup") api.add_resource(UserInfo, "/user/<string:username>") if __name__ == "__main__": create_table() app.run(port=5000, debug=True)
import os import sys sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))) from preference import preference from create_table import create_table from create_db import create_db create_db(preference.db_name) create_table(preference.db_name, preference.table_name)
def create_table(self): create_table(self.cursor) save_page(self.cursor)
"""Примеры использования.""" from create_table import create_table create_table(name="clients") create_table(schema="test_dds", name="clients", distributed_by="birthday", rows_num=5)
def main(): lg.print_logo() ct.create_table() cmd_line()
if __name__ == '__main__': print( 'Программа-скрипт для сбора информации о других аниме-пабликах. Команды:' ) print('1. create_data - создание первичной базы данных') print('2. create_table - создание удобной таблицы первичной базы данных') print('3. pubs_info - подробная информация о каждом паблике') print('4. Нажмите клавишу Enter для выхода') while 1: command = input('Введите команду: ') if command == 'create_data': create_data.create_data(PUBS, TOKEN) print('\nПервичная база данных создана') elif command == 'create_table': DATA = codecs.open(os.path.join(r'.\pub_info', 'data.json'), 'r', encoding='utf-8') create_table.create_table(DATA) print('\nПервичная таблица создана') elif command == 'pubs_info': DATA = codecs.open(os.path.join(r'.\pub_info', 'data.json'), 'r', encoding='utf-8') pubs_info.pubs_info(TOKEN, DATA) print('\nПодробная статистика пабликов создана') elif command == '': sys.exit() else: print('\nТакой команды не существует')
def main(): lg.print_logo() ct.create_table() run_program()