def fetch_word_evaluation_dictionary(): db_connection = create_db_connection() db_cursor = db_connection.cursor() db_cursor.execute('SELECT dict FROM coins') word_eval_dict = db_cursor.fetchone() db_connection.close() return word_eval_dict[0]
def fetch_session_file_content(): db_connection = create_db_connection() cursor = db_connection.cursor() cursor.execute("SELECT (session_blob) FROM session_blob LIMIT 1;") session_file_content = cursor.fetchone() print(datetime.time(datetime.now()), session_file_content[0]) db_connection.close() return session_file_content[0]
def save_unlisted_group(self, group_id): db_connection = create_db_connection() db_cursor = db_connection.cursor() db_cursor.execute( 'INSERT into pump_groups (group_id, name, signal_type) values (%s, %s, %s)', [group_id, 'ADDED USING BOT', 'unknown']) db_connection.commit() db_connection.close()
def save_phone_code_hash(hash): db_connection = create_db_connection() cursor = db_connection.cursor() cursor.execute("DELETE FROM auth_code") db_connection.commit() cursor.execute( "INSERT INTO auth_code(code, launch, code_hash) VALUES (%s, %s, %s);", [-1, False, hash]) db_connection.commit() db_connection.close()
def save_session_file(): print(datetime.time(datetime.now()), 'saving session file') db_connection = create_db_connection() session_file_content = open('telegram.session', 'rb').read() cursor = db_connection.cursor() cursor.execute("DELETE FROM session_blob") db_connection.commit() cursor.execute("INSERT INTO session_blob(session_blob) VALUES (%s);", [session_file_content]) db_connection.commit() db_connection.close()
def save_cross_promo_links(self, found_cross_promo_links): # the db will save only unique records db_connection = create_db_connection() db_cursor = db_connection.cursor() for link in found_cross_promo_links: db_cursor.execute( 'INSERT into unique_cross_promo_links values (%s)', [link]) db_connection.commit() db_connection.close()
def __fetch_auth_data(param): db_connection = create_db_connection() db_cursor = db_connection.cursor() db_cursor.execute('SELECT code, launch, code_hash FROM auth_code') auth_data = db_cursor.fetchall() db_connection.close() # a list containing one tuple if auth_data: return auth_data[0][param] else: return None
def save_processed_message(self, message, group_id, timestamp, receive_time, send_time, processing_time, delay_sec): db_connection = create_db_connection() db_cursor = db_connection.cursor() db_cursor.execute( 'INSERT into message_statistics (message, group_id, send_timestamp, receive_time, send_time, processing_time, delay_seconds) ' 'values (%s, %s, %s, %s, %s, %s, %s)', [ message, group_id, timestamp, receive_time, send_time, processing_time, delay_sec ]) db_connection.commit() db_connection.close()
def create_coin_keywords_eval_dict(): market_names_list = BittrexService().fetch_active_btc_pairs_with_names() db_connection = create_db_connection() markets_eval_dict = [] for market in market_names_list[:10]: # create different permutations of the coin names that are plausible to be used in the tweeted image if market[1].lower().endswith(COIN_SUFFIX): potential_coin_variant = market[1][:-4].lower().capitalize() if len(potential_coin_variant) > 1 and market[1].lower() != potential_coin_variant.lower() and \ potential_coin_variant not in FORBIDDEN_PART_WORDS: market.append(potential_coin_variant) if len(market[1].split(' ')) > 1: potential_coin_variant = market[1].split(' ')[0] if potential_coin_variant not in FORBIDDEN_PART_WORDS: market.append(potential_coin_variant) if market[0].lower() == market[-1].lower(): del market[-1] # convert to definition count punishment partial dictionary current_market_dictionary = [] for index, market_alias in enumerate(market): print(datetime.time(datetime.now()), index, market_alias) if market_alias.lower().endswith(COIN_SUFFIX): # coins with names "*coin" are definitely not proper english words current_market_coin_tuple = (market_alias, 1) else: # calculate the word trust value depending on english dictionary definitions count current_market_word_value = 1 - fetch_word_definitions_count( market_alias) / WORD_VALUE_DENOMINATOR current_market_coin_tuple = (market_alias, current_market_word_value) current_market_dictionary.append(current_market_coin_tuple) print(datetime.time(datetime.now()), "Punishment dictionary for current coin: ", current_market_dictionary) print(datetime.time(datetime.now()), "") markets_eval_dict.append(current_market_dictionary) print(datetime.time(datetime.now()), markets_eval_dict) db_cursor = db_connection.cursor() db_cursor.execute( 'INSERT into coins_dictionary (timestamp, dict) values (%s, %s)', [time.time(), Json(markets_eval_dict)]) db_connection.commit() db_connection.close()
def fetch_all_group_ids(fresh_state_needed): groups_list = [] if fresh_state_needed: db_connection = create_db_connection() db_cursor = db_connection.cursor() db_cursor.execute('SELECT group_id, signal_type FROM pump_groups') groups_list = db_cursor.fetchall() db_connection.close() else: if not _all_groups_list: groups_list = fetch_all_group_ids(True) else: groups_list = _all_groups_list return groups_list
def fetch_all_yobit_coins(fresh_state_needed): coins_list = [] if fresh_state_needed: db_connection = create_db_connection() db_cursor = db_connection.cursor() db_cursor.execute('SELECT coins_list FROM coins WHERE exchange = %s', ['yobit']) coins_list = [ coin.center(len(coin) + 2) for coin in db_cursor.fetchone()[0] ] db_connection.close() else: if not _yobit_coins_list: coins_list = fetch_all_yobit_coins(True) else: coins_list = _yobit_coins_list return coins_list
def save_unknown_group_message(self, cleaned_message): message_dict = cleaned_message.to_dict(recursive=True) db_connection = create_db_connection() try: cleaned_message_dict = self.__clean_message(message_dict) # print(datetime.time(datetime.now()), 'Message after cleaning', cleaned_message_dict, '\n') db_cursor = db_connection.cursor() db_cursor.execute( 'INSERT into traced_messages (timestamp, chat_id, full_message) values (%s, %s, %s)', [ time(), cleaned_message.to_id.channel_id, Json(cleaned_message_dict) ]) except Exception as err: print(datetime.time(datetime.now()), err) finally: db_connection.commit() db_connection.close()
from datetime import datetime from common.database.database_connection import create_db_connection chat_id = input('Input chat ID:') chat_name = input('Input chat name:') db_connection = create_db_connection() db_cursor = db_connection.cursor() db_cursor.execute( 'SELECT full_message FROM traced_messages WHERE chat_id = %s', [chat_id]) rows = db_cursor.fetchall() print(datetime.time(datetime.now()), rows) chat_signal_type = input('Input chat signal type:') db_cursor.execute('DELETE FROM traced_messages WHERE chat_id = %s', [chat_id]) db_cursor.execute('DELETE FROM pump_groups WHERE group_id = %s', [chat_id]) db_cursor.execute( 'INSERT INTO pump_groups (group_id, name, signal_type) VALUES (%s, %s, %s)', [chat_id, chat_name, chat_signal_type]) db_connection.commit() db_connection.close()