def process_entry(processes, key, quit, failed): db_url = get_env('sbhan_db_conn_url') conn = db_manager.connect(db_url) while not quit.is_set(): start = datetime.now() for station in [ station for idx, station in enumerate(STATIONS) if (idx % processes == key) ]: try: process_station(conn, station) except Exception as e: conn = db_manager.connect(db_url) failed.set() logger.error( f'Process {key} has stoped because an error happened\n❗{station} + {e}' ) break length = diff_datetime(start, datetime.now()) print( f'☆☆☆☆☆☆☆☆☆ Round ended in of process {key} - {length} seconds ☆☆☆☆☆☆☆☆☆' ) if length < ROUND_LENGTH: time.sleep(ROUND_LENGTH - length)
def main() -> None: try: user, password, auth_db = parse_login_data() mongo_client: MongoClient = connect(user=user, password=password, auth_db=auth_db) init_db(mongo_client=mongo_client, number_of_plain_entries=NUMBER_OF_PLAIN_ENTRIES, number_of_sha1_entries=NUMBER_OF_SHA1_ENTRIES, number_of_sha256_entries=NUMBER_OF_SHA256_ENTRIES) mongo_client.close() except: print("Failed to generate the test database.")
def save_model(model, exp_count): connection = db_manager.connect(ENV) with connection.cursor() as curs: curs.execute( 'INSERT INTO category_classifier (user_id, model, expense_count, "createdAt", "updatedAt") ' + 'VALUES (%s, %s, %s, now(), now()) ON CONFLICT (user_id) DO UPDATE SET model = EXCLUDED.model, "updatedAt" = now(), expense_count = EXCLUDED.expense_count;', (str(USER_ID), psycopg2.Binary(model), str(exp_count))) connection.commit()
def getExpenses(): connection = db_manager.connect(ENV) with connection.cursor() as curs: curs.execute( 'SELECT amount, date, stores.store_name, COALESCE(category_id, -1) ' + 'FROM expenses LEFT JOIN stores on stores.id = store_id' + ' WHERE user_id = %s ORDER BY category_id;', [USER_ID]) expenses = curs.fetchall() return expenses
def __do_query_to_db(hash_prefix: str, mode: str) -> list: try: prefix_len: int = len(hash_prefix) to_return: list[str] = [] user, password, auth_db = parse_login_data() mongo_client: MongoClient = connect(user=user, password=password, auth_db=auth_db) results: Cursor = search(mongo_client=mongo_client, prefix=hash_prefix, collection_name=mode) for result in results: to_return.append(result[DATA_FIELD][prefix_len:]) results.close() mongo_client.close() return to_return except: return [ERROR]
origins = [ "http://*****:*****@app.get('/') async def root(): return {"message": "Hello World"} @app.get('/stations') async def get_stations(): cur = conn.cursor()
# -*- coding: utf-8 -*- # Импорт класса Server from server_files.server_actor import ServerActor # Получение config.py import config from db_manager import connect # from multiprocessing import Process connection = connect() # db_manager. server2 = ServerActor( api_token=config.vk_api_token, server_name="my_server", role='reader', # 'reader' db_connection=connection) # vk_api_token - API токен, который мы ранее создали # 197901530 - id сообщества-бота # "server1" - имя сервера # role - функционал сервера # bot1 = Process(target=server1.start) # bot1.start() # bot1.join() server2.start()