Ejemplo n.º 1
0
def modify_schedule(calendar_uid, current, end, begin, account_id):
    summarys = {"kr": "근무시간", "jp": "勤務時間", "en": "Working hours"}

    calendar_data = make_icalendar_data(calendar_uid, summarys[LOCAL], current,
                                        end, begin, account_id)
    body = {"ical": calendar_data}

    calendar_id = get_value(API_BO["calendar"]["name"], None)
    if calendar_id is None:
        LOGGER.error("get calendar from cached failed.")
        raise HTTPError(500, "internal error. get calendar is failed.")

    url = API_BO["calendar"]["modify_schedule_url"]
    url = url.replace("_EXTERNAL_KEY_", load_external_key())
    url = url.replace("_CALENDAR_ID_", calendar_id)
    url = url.replace("_CALENDAR_UUID_", calendar_uid)

    headers = create_headers()
    response = auth_put(url, data=json.dumps(body), headers=headers)
    if response.status_code != 200:
        LOGGER.error("modify schedules failed. url:%s text:%s body:%s", url,
                     response.text, response.content)
        raise HTTPError(500,
                        "internal error. create schedule http code error.")

    LOGGER.info("modify schedules. url:%s text:%s body:%s", url, response.text,
                response.content)

    tmp_req = json.loads(response.content)
    if tmp_req["result"] != "success":
        LOGGER.error("modify schedule failed. url:%s text:%s body:%s", url,
                     response.text, response.content)
        raise HTTPError(500, "internal error. http response error.")
Ejemplo n.º 2
0
def replace_url_bot_no(url):
    bot_no = get_value("bot_no", None)
    if bot_no is None:
        LOGGER.info("internal error. bot no is None")
        raise HTTPError(500, "internal error. bot no is None")

    url = url.replace("_BOT_NO_", bot_no)
    return url
Ejemplo n.º 3
0
def sign(account_id):
    if account_id is None:
        LOGGER.error("account_id is None.")
        return False
    rich_menu_id = get_value(RICH_MENUS[LOCAL]["name"], None)
    if rich_menu_id is None:
        LOGGER.error("get rich_menu_id failed.")
        raise Exception("get rich_menu_id failed.")

    return set_user_specific_rich_menu(rich_menu_id, account_id)
Ejemplo n.º 4
0
def create_schedule(current, end, begin, account_id, title):
    """
    create schedule.
    reference: https://developers.worksmobile.com/kr/document/100702703?lang=ko

    :return: schedule id.
    """

    uid = str(uuid.uuid4()) + account_id
    schedule_data = make_icalendar_data(uid, title, current, end, begin,
                                        account_id, True)
    body = {"ical": schedule_data}

    calendar_id = get_value(API_BO["calendar"]["name"], None)
    if calendar_id is None:
        LOGGER.error("get calendar from cached failed.")
        raise HTTPError(500, "internal error. get calendar is failed.")

    headers = create_headers()
    url = API_BO["calendar"]["create_schedule_url"]
    url = url.replace("_EXTERNAL_KEY_", load_external_key())
    url = url.replace("_CALENDAR_ID_", calendar_id)

    response = auth_post(url, data=json.dumps(body), headers=headers)
    if response.status_code != 200:
        LOGGER.error("create schedules failed. url:%s text:%s body:%s", url,
                     response.text, response.content)
        raise HTTPError(500,
                        "internal error. create schedule http code error.")

    tmp_req = json.loads(response.content)
    if tmp_req["result"] != "success":
        LOGGER.error("create schedule failed. url:%s text:%s body:%s", url,
                     response.text, response.content)
        raise HTTPError(500, "internal error. http response error.")

    LOGGER.info("create schedule. url:%s text:%s body:%s", url, response.text,
                response.content)

    return_value = tmp_req.get("returnValue", None)
    if return_value is None:
        LOGGER.error("create schedule failed. url:%s text:%s body:%s", url,
                     response.text, response.content)
        raise HTTPError(500, "internal error. create schedule content error.")

    schedule_uid = return_value.get("icalUid", None)
    if schedule_uid is None:
        LOGGER.error("create schedule failed. url:%s text:%s body:%s", url,
                     response.text, response.content)
        raise HTTPError(500, "internal error. create schedule content error.")
    return schedule_uid
Ejemplo n.º 5
0
def create_schedule(current, end, begin, account_id):
    summarys = {"kr": "출근시간", "jp": "出勤時間", "en": "Clock-in time"}

    uid = str(uuid.uuid4()) + account_id
    schedule_data = make_icalendar_data(uid, summarys[LOCAL], current, end,
                                        begin, account_id, True)
    body = {"ical": schedule_data}

    calendar_id = get_value(API_BO["calendar"]["name"], None)
    if calendar_id is None:
        LOGGER.error("get calendar from cached failed.")
        raise HTTPError(500, "internal error. get calendar is failed.")

    headers = create_headers()
    url = API_BO["calendar"]["create_schedule_url"]
    url = url.replace("_EXTERNAL_KEY_", load_external_key())
    url = url.replace("_CALENDAR_ID_", calendar_id)

    response = auth_post(url, data=json.dumps(body), headers=headers)
    if response.status_code != 200:
        LOGGER.error("create schedules failed. url:%s text:%s body:%s", url,
                     response.text, response.content)
        raise HTTPError(500,
                        "internal error. create schedule http code error.")

    tmp_req = json.loads(response.content)
    if tmp_req["result"] != "success":
        LOGGER.error("create schedule failed. url:%s text:%s body:%s", url,
                     response.text, response.content)
        raise HTTPError(500, "internal error. http response error.")

    LOGGER.info("create schedule. url:%s text:%s body:%s", url, response.text,
                response.content)

    return_value = tmp_req.get("returnValue", None)
    if return_value is None:
        LOGGER.error("create schedule failed. url:%s text:%s body:%s", url,
                     response.text, response.content)
        raise HTTPError(500, "internal error. create schedule content error.")

    schedule_uid = return_value.get("icalUid", None)
    if schedule_uid is None:
        LOGGER.error("create schedule failed. url:%s text:%s body:%s", url,
                     response.text, response.content)
        raise HTTPError(500, "internal error. create schedule content error.")
    return schedule_uid
Ejemplo n.º 6
0
def sign(account_id):
    """
    Set up rich menu for chat with users.
    Check also: calendar_bot/model/data.py
    reference: https://developers.worksmobile.com/jp/document/1005040?lang=en

    :param account_id: user account id
    """
    if account_id is None:
        LOGGER.error("account_id is None.")
        return False
    rich_menu_id = get_value("rich_menu", None)
    if rich_menu_id is None:
        LOGGER.error("get rich_menu_id failed.")
        raise Exception("get rich_menu_id failed.")

    return set_user_specific_rich_menu(rich_menu_id, account_id)
Ejemplo n.º 7
0
def modify_schedule(calendar_uid, current, end, begin, account_id):
    """
    modify schedule.
    reference: https://developers.worksmobile.com/kr/document/100702704?lang=ko

    :return: schedule id.
    """

    calendar_data = make_icalendar_data(calendar_uid, "Working hours", current,
                                        end, begin, account_id)
    body = {"ical": calendar_data}

    calendar_id = get_value(API_BO["calendar"]["name"], None)
    if calendar_id is None:
        LOGGER.error("get calendar from cached failed.")
        raise HTTPError(500, "internal error. get calendar is failed.")

    url = API_BO["calendar"]["modify_schedule_url"]
    url = url.replace("_EXTERNAL_KEY_", load_external_key())
    url = url.replace("_CALENDAR_ID_", calendar_id)
    url = url.replace("_CALENDAR_UUID_", calendar_uid)

    headers = create_headers()
    response = auth_put(url, data=json.dumps(body), headers=headers)
    if response.status_code != 200:
        LOGGER.error("modify schedules failed. url:%s text:%s body:%s", url,
                     response.text, response.content)
        raise HTTPError(500,
                        "internal error. create schedule http code error.")

    LOGGER.info("modify schedules. url:%s text:%s body:%s", url, response.text,
                response.content)

    tmp_req = json.loads(response.content)
    if tmp_req["result"] != "success":
        LOGGER.error("modify schedule failed. url:%s text:%s body:%s", url,
                     response.text, response.content)
        raise HTTPError(500, "internal error. http response error.")
Ejemplo n.º 8
0
def load_time_zone():
    time_zone = get_value("offsetTimeZone", None)
    if time_zone is None:
        time_zone = set_tz()

    return time_zone
Ejemplo n.º 9
0
def get_tz():
    offset_time_zone = get_value("offsetTimeZone", None)
    return offset_time_zone
Ejemplo n.º 10
0
def get_token():
    return get_value("token", None)
Ejemplo n.º 11
0
def get_external_key():
    external_key = get_value("externalKey", None)
    return external_key