Example #1
0
def compare_licence_hashes_is_same():
    billing_api_url = get_billig_url()
    billing_api_licence_url = "/licence/"
    endpoint_for_get_licence_time = billing_api_url + billing_api_licence_url + show_bot_id(
    )

    if login_on_billing() == {
            'message': "User {} doesn't exist".format(show_bot_id())
    }:
        auth_token_access = registration_on_billing()["access_token"]
    else:
        auth_token_access = login_on_billing()["access_token"]

    auth_token_access_bearer = "Bearer " + auth_token_access
    headers_access = {"Authorization": auth_token_access_bearer}

    bot_hash_dict = requests.get(endpoint_for_get_licence_time,
                                 headers=headers_access,
                                 verify=True).json()
    bot_hash_on_billing = bot_hash_dict["users"][0]["bot_hash"]

    if bot_hash_on_billing is None:
        write_bot_hash_if_null()
        bot_hash_dict = requests.get(endpoint_for_get_licence_time,
                                     headers=headers_access,
                                     verify=True).json()
        bot_hash_on_billing = bot_hash_dict["users"][0]["bot_hash"]

    if hash_licence() != bot_hash_on_billing:
        return False
    else:
        return True
Example #2
0
def write_bot_hash_if_null():

    secret_for_write_hash = "K_z1Lter7c-33tr76jUujXEqIU12uP1UsAYAcyPgZ5A="

    billing_api_url = get_billig_url()
    billing_api_write_licence_url = "/updatehash"
    endpoint_for_write_bot_hash = billing_api_url + billing_api_write_licence_url

    if login_on_billing() == {
            'message': "User {} doesn't exist".format(show_bot_id())
    }:
        auth_token_access = registration_on_billing()["access_token"]
    else:
        auth_token_access = login_on_billing()["access_token"]

    auth_token_access_bearer = "Bearer " + auth_token_access
    headers_access = {"Authorization": auth_token_access_bearer}
    bot_hash_dict = {
        "bot_id": show_bot_id(),
        "bot_hash": hash_licence(),
        "secret_for_write_hash": secret_for_write_hash
    }

    requests.post(endpoint_for_write_bot_hash,
                  json=bot_hash_dict,
                  headers=headers_access,
                  verify=True).json()
Example #3
0
def adv_messages():
    try:
        adv_messages = requests.get(get_billig_url() + messages_url).json()
        adv = []
        for i in adv_messages["messages"]:
            for k, v in i.items():
                if k == "adv":
                    adv.append(v)

        notificator(adv[-1:][0])  # first fresh message

    except requests.exceptions.RequestException:
        pass
    except Exception:
        pass
Example #4
0
def login_on_billing():

    secret_for_bot_login = "******"

    billing_api_url = get_billig_url()
    billing_api_login_url = "/botlogin"
    endpoint_for_login = billing_api_url + billing_api_login_url
    login_data_json = {
        "bot_id": show_bot_id(),
        "secret_for_bot_login": secret_for_bot_login
    }

    server_answer = requests.post(endpoint_for_login,
                                  json=login_data_json,
                                  verify=True).json()

    return server_answer
Example #5
0
def registration_on_billing():

    secret_for_bot_registration = "LXORWIiKFXUSBO2Ip_sVKpRByuwDVhSOt9nTgopUoQ8="

    billing_api_url = get_billig_url()
    billing_api_registration_url = "/registration"
    endpoint_for_registration = billing_api_url + billing_api_registration_url
    registration_data_json = {
        "bot_id": show_bot_id(),
        "bot_hash": hash_licence(),
        "secret_for_bot_registration": secret_for_bot_registration
    }

    server_answer = requests.post(endpoint_for_registration,
                                  json=registration_data_json,
                                  verify=True).json()

    return server_answer
Example #6
0
def info_messages():
    global inf_messages
    try:
        x = requests.get(get_billig_url() + messages_url).json()
        if x == inf_messages:
            pass
        else:
            inf_messages = x

            info = []
            for i in inf_messages["messages"]:
                for k, v in i.items():
                    if k == "info":
                        info.append(v)

            notificator(info[-1:][0])  # first fresh message from db

    except requests.exceptions.RequestException:
        pass
    except Exception:
        pass
Example #7
0
def get_encrypted_licence_time(auth_token_access):

    billing_api_url = get_billig_url()
    billing_api_licence_url = "/licence/"
    endpoint_for_get_licence_time = billing_api_url + billing_api_licence_url + show_bot_id(
    )

    auth_token_access_bearer = "Bearer " + auth_token_access
    headers_access = {"Authorization": auth_token_access_bearer}

    bot_licence = requests.get(endpoint_for_get_licence_time,
                               headers=headers_access,
                               verify=True).json()
    ecnrypted_licence_time = bot_licence["users"][0]["bot_licence"]

    if ecnrypted_licence_time is None:
        return "Null"
    else:
        key = secret_for_encruption_licence_time + show_bot_id()
        f = Fernet(key)
        ecnrypted_licence_time = ecnrypted_licence_time.encode()
        x = f.decrypt(ecnrypted_licence_time)
        x = x.decode()
        return x