def get_stage(user_ip, date_from, date_to, payment_systems, action): current_stage, max_stage, report_table_name = database.get_users_table( user_ip) database.drop_table(report_table_name) if action == 'back': current_stage, max_stage = form_processor.make_report( date_from, date_to, report_table_name, payment_systems, latest=False, stage=current_stage - 1) elif action == 'forward': current_stage, max_stage = form_processor.make_report( date_from, date_to, report_table_name, payment_systems, latest=False, stage=current_stage + 1) database.update_users_table(user_ip, current_stage, max_stage, report_table_name) rows = database.get_report_table_rows(report_table_name) previous_disable = True if current_stage < 2 else False next_disable = True if current_stage >= max_stage else False return rows, previous_disable, next_disable, current_stage, max_stage
def make_daily_analysis(date_interval): payment_temp_table = 'payment_temp' choco_temp_table = 'choco_temp' first_error_table = 'first_error' second_error_table = 'second_error' third_error_table = 'third_error' for d in date_interval: # transactions from payment systems database.create_payment_trans_temp_table(payment_temp_table) data = database.get_daily_payment_trans(d) database.update_payment_trans_temp_table(payment_temp_table, data) # transactions from choco's servers transactions = get_api_response(d) database.create_choco_temp_table(choco_temp_table) date, date_created, order_id, payment_amount, payment_type, payment_reference, status, key_1, key_2 = read_json.read_api_response( transactions) database.update_choco_temp_table(choco_temp_table, date, date_created, order_id, payment_amount, payment_type, payment_reference, status, key_1, key_2) # магия вне Хогвартса (анализ) # temporary tables for errors database.create_error_temp_table(first_error_table) database.create_error_temp_table(second_error_table) database.create_error_temp_table(third_error_table) # first error type first_error_data = database.get_first_second_errors(payment_temp_table, choco_temp_table) database.update_first_error_temp_table(first_error_table, first_error_data) # second error type second_error_data = database.get_first_second_errors(choco_temp_table, payment_temp_table) database.update_second_error_temp_table(second_error_table, second_error_data) # third error type third_error_payment, third_error_choco, keys = database.get_third_error(first_error_table, second_error_table) database.update_third_error_temp_tablle(third_error_table, third_error_payment, third_error_choco) # clear first and second error tables from third error type database.clear_error_table_by_keys(first_error_table, keys) database.clear_error_table_by_keys(second_error_table, keys) # combine three tables with errors into one errors = combine_errors(first_error_table, second_error_table, third_error_table) daily_table_name = get_daily_table_name(d) database.create_daily_analysis_table(daily_table_name) database.update_daily_tables_table(d) database.update_daily_analysis_table(daily_table_name, errors) # магия оканчивается # clearing database from temporary tables database.drop_table(payment_temp_table) database.drop_table(choco_temp_table) database.drop_table(first_error_table) database.drop_table(second_error_table) database.drop_table(third_error_table)
def make_history_table(key, value): value = str(value) dates = database.get_daily_tables() daily_tables = list() for date in dates: date = date[0] table_name = get_daily_table_name(date) daily_tables.append(table_name) daily_tables.sort() full_list = list() for table in daily_tables: transactions = database.get_trans_by_key_value(table, key, value) full_list.append(transactions) full_list = list(itertools.chain.from_iterable(full_list)) # writing to table history_table_name = get_history_table_name(key, value) database.drop_table(history_table_name) database.create_report_table(history_table_name) database.update_report_table(history_table_name, full_list) return history_table_name
def main(): service, user_id, label_ids, status = GmailCredential() if status: all_email_ids = ListMessagesWithLabels(service, user_id, label_ids) msg_id = all_email_ids[0] database.drop_table() database.create_table() print("Building the email Databse") print("") print("-" * 98) for count in tqdm(range(500)): GetMessage(service, user_id, all_email_ids[count], count) # time.sleep(1) # sys.stdout.write("-") # sys.stdout.flush() # sys.stdout.write("]\n") # this ends the progress ba print("-" * 98) print("") print("Latest 100 emails has been feteched from GMAIL !!!!!")
def make_report(date_from, date_to, report_table_name, payment_systems,latest=True, stage=1): date_interval = get_date_interval(date_from, date_to) make_daily_analysis(date_interval) make_log(date_interval) log_list = list() for d in date_interval: log = database.get_log_by_date(d) log = log[0][0].split() log_list.append(log) log_list = clear_log(log_list) if latest: stage = 0 stage_list = list() for log in log_list: stage_list.append(log[stage-1]) report_table = list() for i in range(len(date_interval)): daily_table_name = get_daily_table_name(date_interval[i]) temp_table = database.get_daily_analysis_table(daily_table_name, payment_systems, latest=False, queue=stage_list[i]) report_table += temp_table database.drop_table(report_table_name) database.create_report_table(report_table_name) database.update_report_table(report_table_name, report_table) return stage, len(log_list[0])
def print_usage(): print('Incorrect number of arguments.') print('Script can be invoked like:') print(' ~:$ python3 manage.py adduser username:password') print(' ~:$ python3 manage.py userdel username:password') print(' ~:$ python3 manage.py getusers') print(' ~:$ python3 manage.py load_default') sys.exit(1) if __name__ == '__main__': if len(sys.argv) == 2 and sys.argv[1] == 'load_default': connection = database.connect() for table_name in 'users', 'tasks': database.drop_table(connection, table_name) database.create_table(connection, table_name) database.load_default(connection, table_name) connection.close() elif len(sys.argv) == 2 and sys.argv[1] == 'getusers': connection = database.connect() for user, password in database.get_user_credentials(connection): print('user:password -> {0}:{1}'.format(user, password)) connection.close() elif len(sys.argv) == 3 and sys.argv[1] == 'adduser': connection = database.connect() database.insert_user(connection, sys.argv[2]) connection.close() elif len(sys.argv) == 3 and sys.argv[1] == 'userdel': connection = database.connect() database.delete_user(connection, sys.argv[2])
def tearDown(self): database.drop_table()
import database as db import numpy as np import pandas as pd training_dataset = '/Volumes/Seagate/kaggle/facial-keypoints-detection/training.csv' testing_dataset = '/Volumes/Seagate/kaggle/facial-keypoints-detection/test.csv' db_name = 'facial_keysets.db' ################# conn = db.create_connection(db_name) ################# db.drop_table('FACIAL_KEYPOINTS', conn) db.drop_table('NEW_IMAGES', conn) db.drop_table('IMAGES', conn) ################# new_table = db.table('IMAGES') new_table.add_column('IMAGE_ID', 'INTEGER', is_primary=True, is_foreign=None, is_done=False) new_table.add_column('IMAGE_STRING', 'BLOB', is_primary=False, is_foreign=None, is_done=True) new_table.commit(conn) ################# df = pd.read_csv(training_dataset)
def surprise_tool(): if database.check_if_attendance_table_exists().get("exists"): database.drop_table() database.create_table() else: database.create_table()