Esempio n. 1
0
def get_time_zone():
    """
    Get time zone according to administrator account.
    reference: https://developers.worksmobile.com/kr/document/100300528?lang=en
    """
    external_key = load_external_key()
    time_zone_url = API_BO["TZone"]["time_zone_url"]
    time_zone_url = time_zone_url.replace("DOMAIN_ID", str(DOMAIN_ID))
    time_zone_url = time_zone_url.replace("EXTERNAL_KEY", external_key)

    headers = {
        "content-type": "application/json",
        "charset": "UTF-8",
        "consumerKey": OPEN_API["consumerKey"]
    }

    response = auth_get(time_zone_url, headers=headers)
    if response.status_code != 200 or response.content is None:
        LOGGER.info("get external key failed. url:%s text:%s body:%s",
                    time_zone_url, response.text, response.content)
        raise Exception("get timezone. http code error.")

    tmp_req = json.loads(response.content)
    time_zone = tmp_req.get("timeZone", None)
    if time_zone is None:
        raise Exception("get timezone. no timeZone filed.")
    return time_zone
Esempio n. 2
0
def get_rich_menus():
    """
    Get rich menus
    reference: https://developers.worksmobile.com/kr/document/100504004?lang=en

    :return: rich menu list
    """
    headers = API_BO["headers"]
    headers["consumerKey"] = OPEN_API["consumerKey"]
    url = API_BO["rich_menu_url"]
    url = utils.replace_url_bot_no(url)

    LOGGER.info("push message begin. url:%s", url)
    response = auth_get(url, headers=headers)
    if response.status_code != 200:
        LOGGER.info("push message failed. url:%s text:%s body:%s", url,
                    response.text, response.content)
        return None

    LOGGER.info("push message success. url:%s txt:%s body:%s", url,
                response.text, response.content)

    tmp = json.loads(response.content)
    if "richmenus" in tmp:
        return tmp["richmenus"]

    return None
Esempio n. 3
0
def get_rich_menus():
    headers = API_BO["headers"]
    headers["consumerKey"] = OPEN_API["consumerKey"]
    url = API_BO["rich_menu_url"]
    url = utils.replace_url_bot_no(url)

    LOGGER.info("push message begin. url:%s", url)
    response = auth_get(url, headers=headers)
    if response.status_code != 200:
        LOGGER.info("push message failed. url:%s text:%s body:%s",
                    url, response.text, response.content)
        return None

    LOGGER.info("push message success. url:%s txt:%s body:%s",
                url, response.text, response.content)

    tmp = json.loads(response.content)
    if "richmenus" in tmp:
        return tmp["richmenus"]

    return None
Esempio n. 4
0
def get_time_zone():
    external_key = load_external_key()
    time_zone_url = API_BO["TZone"]["time_zone_url"]
    time_zone_url = time_zone_url.replace("DOMAIN_ID", str(DOMAIN_ID))
    time_zone_url = time_zone_url.replace("EXTERNAL_KEY", external_key)

    headers = {
        "content-type": "application/json",
        "charset": "UTF-8",
        "consumerKey": OPEN_API["consumerKey"]
    }

    response = auth_get(time_zone_url, headers=headers)
    if response.status_code != 200 or response.content is None:
        LOGGER.info("get external key failed. url:%s text:%s body:%s",
                    time_zone_url, response.text, response.content)
        raise Exception("get timezone. http code error.")

    tmp_req = json.loads(response.content)
    time_zone = tmp_req.get("timeZone", None)
    if time_zone is None:
        raise Exception("get timezone. no timeZone filed.")
    return time_zone