Example #1
0
def start_counting(data):
    # запуск расчета баз
    PNN = 'ПНН' if data['CHECKED'] == True else 'без ПНН'
    connect_bases = []
    for base in data['BASES']:
        host = redis_store.hmget(base[:3], ['host'])[0]
        try:
            if platform == 'linux':
                call(["ping", "-c", "1", host], timeout=0.25, stdout=DEVNULL)
            else:
                call(["ping", "-n", "1", host], timeout=0.25, stdout=DEVNULL)
        except TimeoutExpired:
            basename = redis_store.hmget(base[:3], ['name'])[0]
            emit('server_response', {
                'info': 'button',
                'procedure': 'error',
                'data': basename
            })
            continue
        connect_bases.append(base)

        conn = get_connection(base)
        cursor = conn.cursor()
        if PNN == 'ПНН':
            cursor.execute(
                querySQL.sql_update3,
                (1, 1, 'Запуск обработок: 2. Выполнить расчет с ПНН'))
        else:
            cursor.execute(
                querySQL.sql_update3,
                (1, 1, 'Запуск обработок: 1. Выполнить расчет без ПНН'))
        conn.commit()
        conn.close()
        # minutes = redis_store.hmget(base, ['interval'])[0]
        # check_time = (datetime.now()+timedelta(minutes=int(minutes))).strftime('%d.%m.%Y %H:%M:%S')
        check_time = (datetime.now()).strftime(
            '%d.%m.%Y %H:%M:%S')  # DELETE THIS ROW
        redis_store.hmset(base, {
            'check_time': check_time,
            'PNN': PNN,
            'status': '1'
        })  # need to check
    if len(connect_bases) > 0:
        emit('server_response', {
            'info': 'button',
            'procedure': 'start_counting',
            'data': connect_bases
        },
             broadcast=True)
Example #2
0
def change_period(data):
    # изменение даты запрета редактирования
    time = datetime.strptime('01.' + data['TIME'].replace('.2', '.4'),
                             '%d.%m.%Y')
    if data['CHECKED'] == True:
        checked = 1
        PO = '(v)'
    else:
        checked = 0
        PO = '( )'
    connect_bases = []
    for base in data['BASES']:
        host = redis_store.hmget(base[:3], ['host'])[0]
        try:
            if platform == 'linux':
                call(["ping", "-c", "1", host], timeout=0.25, stdout=DEVNULL)
            else:
                call(["ping", "-n", "1", host], timeout=0.25, stdout=DEVNULL)
        except TimeoutExpired:
            basename = redis_store.hmget(base[:3], ['name'])[0]
            emit('server_response', {
                'info': 'button',
                'procedure': 'error',
                'data': basename
            })
            continue
        connect_bases.append(base)

        conn = get_connection(base)
        cursor = conn.cursor()
        cursor.execute(querySQL.sql_update2, (time, checked))
        conn.commit()
        conn.close()

        redis_store.hmset(base, {'period': data['TIME'], 'PO': PO})

    if len(connect_bases) > 0:
        emit('server_response', {
            'info': 'button',
            'procedure': 'change_period',
            'data': connect_bases
        },
             broadcast=True)
Example #3
0
def authenticate():
    username = request.form.get("username")
    uuid = request.form.get("uuid")
    one_time_code = request.form.get("one_time_code")

    if not (username and uuid and one_time_code):
        return "ERROR - INVALID INFO"
    key = redis_store.get(username + ":temp_key")
    correct_uuid = redis_store.hmget(username, "uuid")[0]
    if not (one_time_code and uuid) or uuid != correct_uuid or (key != one_time_code):
        return "INCORRECT AUTH INFO"

    redis_store.setex(one_time_code, username, 30)
    return "valid login!"
Example #4
0
def get_code():
    username = session.get("username")
    if username:
        if not redis_store.get(username + ":pinged"):
            token_hex = redis_store.hmget(username, "push_key")[0]
            redis_store.setex(username + ":pinged", True, 60)
            random_str = str(random.randint(1, 100000000))  #''.join([x % 10 for x in os.urandom(8)])
            send_notification(token_hex, random_str)
            redis_store.setex(username + ":temp_key", random_str, 30)

            return random_str

    code_bytes = os.urandom(128)
    code = "".join(map(lambda x: string.ascii_letters[ord(x) % len(string.ascii_letters)], code_bytes))
    if username:
        redis_store.setex(username + ":temp_key", str(code), 30)
    else:
        redis_store.setex(code, False, 30)

    return str(code)
Example #5
0
def server_response():
    # проверка баз на окончание расчета
    current_bases = redis_store.smembers('current_bases')
    complite_bases = []

    grz = redis_store.hmget('grz', ['name', 'host', 'interval'])
    dbk = redis_store.hmget('dbk', ['name', 'host', 'interval'])
    lvt = redis_store.hmget('lvt', ['name', 'host', 'interval'])
    usm = redis_store.hmget('usm', ['name', 'host', 'interval'])

    grz_work = redis_store.hmget(
        'grz_work', ['period', 'PO', 'check_time', 'PNN', 'status', 'cache'])
    grz_test = redis_store.hmget(
        'grz_test', ['period', 'PO', 'check_time', 'PNN', 'status', 'cache'])
    dbk_work = redis_store.hmget(
        'dbk_work', ['period', 'PO', 'check_time', 'PNN', 'status', 'cache'])
    dbk_test = redis_store.hmget(
        'dbk_test', ['period', 'PO', 'check_time', 'PNN', 'status', 'cache'])
    lvt_work = redis_store.hmget(
        'lvt_work', ['period', 'PO', 'check_time', 'PNN', 'status', 'cache'])
    lvt_test = redis_store.hmget(
        'lvt_test', ['period', 'PO', 'check_time', 'PNN', 'status', 'cache'])
    usm_work = redis_store.hmget(
        'usm_work', ['period', 'PO', 'check_time', 'PNN', 'status', 'cache'])
    usm_test = redis_store.hmget(
        'usm_test', ['period', 'PO', 'check_time', 'PNN', 'status', 'cache'])

    for base in redis_store.smembers('current_bases'):
        for operating_mode in ['work', 'test']:
            if redis_store.hmget(
                    base + '_' + operating_mode, 'status'
            )[0] == '1':  # если у базы статус "идет расчет", то проверяем по документам начисления и льгот
                str_date = redis_store.hmget(base + '_' + operating_mode,
                                             ['check_time'])[0]
                check_time = datetime.strptime(str_date, '%d.%m.%Y %H:%M:%S')
                if check_time < datetime.now():
                    str_date = redis_store.hmget(base + '_' + operating_mode,
                                                 ['period'])[0]
                    date = datetime.strptime(
                        '01.' + str_date.replace('.2', '.4'), '%d.%m.%Y')
                    PNN = redis_store.hmget(base + '_' + operating_mode,
                                            ['PNN'])[0]
                    host = redis_store.hmget(base, ['host'])[0]
                    try:
                        if platform == 'linux':
                            call(["ping", "-c", "1", host],
                                 timeout=0.25,
                                 stdout=DEVNULL)
                        else:
                            call(["ping", "-n", "1", host],
                                 timeout=0.25,
                                 stdout=DEVNULL)
                    except TimeoutExpired:
                        continue
                    conn = get_connection(base + '_' + operating_mode)
                    cursor = conn.cursor()
                    cursor.execute(querySQL.sql_select10, (
                        date,
                        'Абоненты с групповым измерительным оборудованием (создано обработкой)',
                        'Абоненты без групповых счетчиков (создано обработкой)'
                    ))
                    result = cursor.fetchone()
                    if result[
                            'STATUS'] == 1:  # если количество проведенных документов начислений равно общему количеству документов за установленный учетный месяц
                        if PNN == 'ПНН':
                            cursor.execute(querySQL.sql_update3, (
                                0, 1,
                                'Запуск обработок: 2. Выполнить расчет с ПНН'))
                        else:
                            cursor.execute(querySQL.sql_update3, (
                                0, 1,
                                'Запуск обработок: 1. Выполнить расчет без ПНН'
                            ))
                        conn.commit()
                        redis_store.hmset(base + '_' + operating_mode, {
                            'check_time': '',
                            'status': '2'
                        })  # меняем статус базы на "расчет завершен"
                    conn.close()
            elif redis_store.hmget(
                    base + '_' + operating_mode,
                    'status')[0] == '2':  # если у базы "расчет завершен"
                complite_bases.append(base + '_' + operating_mode)
    emit('server_response', {
        'info': 'server',
        'data': complite_bases
    },
         broadcast=True)


# if __name__ == '__main__':
#     socketio.run(app)