def main():

    print('Начало работы: {}'.format(
        datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
    count_processed = 0
    count_insert = 0
    count_update = 0
    count_tv = 0
    count_tech_data = 0
    SQL.create_data_sessions()
    SQL.create_abon_onyma()
    options = {
        'table_name': 'abon_dsl',
        'str1': 'account_name, tv, hostname, board, port',
        'str2': 'account_name IS NOT NULL'
    }
    account_list = SQL.get_table_data(**options)
    if len(account_list) == 0:
        print('\n!!! Необходимо сформировать таблицу abon_dsl !!!\n')
        return
    onyma_param_list = get_onyma_params()
    arguments = [(account_list[x::Settings.threads_count], onyma_param_list)
                 for x in range(0, Settings.threads_count)]
    while True:
        try:
            arguments.remove(((), onyma_param_list))
        except:
            break

    with ThreadPoolExecutor(max_workers=Settings.threads_count) as executor:
        result = executor.map(run, arguments)

    for count in result:
        count_processed += count[0]
        count_insert += count[1]
        count_update += count[2]
        count_tv += count[3]
        count_tech_data += count[4]

    print('Обработано: {}'.format(count_processed))
    print('Добавлено: {}'.format(count_insert))
    print('Обновлено данных Онимы: {}'.format(count_update))
    print('Обнаружено ТВ: {}'.format(count_tv))
    print('Обновлено тех. данных: {}'.format(count_tech_data))

    options = {
        'table_name':
        'data_sessions',
        'str1':
        'date < DATE_ADD(CURRENT_DATE(), INTERVAL -{} DAY)'.format(
            Settings.days)
    }
    SQL.delete_table(**options)
    print('Завершение работы: {}'.format(
        datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
    print('---------\n')
Beispiel #2
0
def main():
    # Просмотр файлов в директории in/argus/
    argus_file_list = ['in' + os.sep + 'argus' + os.sep + x for x in os.listdir('in' + os.sep + 'argus')]
    
    # Просмотр файлов в директории in/onyma/
    onyma_file_list = ['in' + os.sep + 'onyma' + os.sep + x for x in os.listdir('in' + os.sep + 'onyma')]  
    
    if len(argus_file_list) == 0 or len(onyma_file_list) == 0:
        return
    
    print("Начало работы: {}".format(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
    SQL.create_abon_dsl(drop=True)
    SQL.create_abon_onyma(drop=True)    
    
    # Обработка файлов в директории in/argus/
    argus_files(argus_file_list)
    delete_files(argus_file_list)
    
    # Обработка файлов в директории in/onyma/
    onyma_file(onyma_file_list)
    delete_files(onyma_file_list)
    
    # Заполнение полей bill, dmid, tmid таблицы abon_onyma
    options = {'table_name': 'abon_dsl',
               'str1': 'account_name',
               'str2': 'account_name IS NOT NULL'}
    account_list = SQL.get_table_data(**options)
    if len(account_list) == 0:
        print('\n!!! Не сформирована таблица abon_dsl !!!\n')
        return
    
    arguments = [account_list[x::Settings.threads_count]  for x in range(0,  Settings.threads_count)]
    print('Получение данных из Онимы для таблицы abon_onyma...')
    with ThreadPoolExecutor(max_workers=Settings.threads_count) as executor:
        result = executor.map(run_define_param, arguments)
    count = 0
    for i in result:
        count += i
    print('Обработано: {}'.format(count))
    
    # Заполнение тарифов в abon_dsl
    print('Получение данных из Онимы для заполнения тарифов...')
    with ThreadPoolExecutor(max_workers=Settings.threads_count) as executor:
        result = executor.map(run_define_speed, arguments)
    count = 0
    for i in result:
        count += i
    print('Обработано: {}'.format(count))    
    print("Завершение работы: {}".format(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
    print('---------\n')
Beispiel #3
0
def get_current_ports():
    #
    # Функция получения текущих значений портов для учетных имен
    # возвращает словарь вида {'account_name': {'hostname': '', 'board': '', 'port': ''}}
    #
    result = {}
    # Получение данных из базы данных
    options = {'table_name': 'abon_onyma',
               'str1': 'account_name, hostname, board, port',
               'str2': 'account_name IS NOT NULL'}
    accounts = SQL.get_table_data(**options)
    for account in accounts:
        result[account[0]] = {'hostname': account[1], 'board': account[2], 'port': account[3]}
    return result