コード例 #1
0
def confirm_out_message(user_time, total_hours, total_minutes):
    date_time = local_date_time(user_time)

    fmt = _(" ")
    str_hours = ""
    hours_content = get_i18n_content(fmt, "confirm_out")

    if total_hours != 0:
        str_hours = "{total_hours} hours and "
        fmt = _("{total_hours} hours and ")
        hours_content = get_i18n_content(fmt, "confirm_out")
        for key in hours_content:
            hours_content[key] = hours_content[key].format(
                total_hours=total_hours)

    fmt1 = _(
        "Clock-out time has been registered. "
        "The total working hours for {date} is {total_hours}{total_minutes} minutes."
    )
    texts = get_i18n_content(fmt1, "confirm_out")

    fmt2 = _("%A, %B %d")
    dates = get_i18n_content(fmt2, "confirm_out")

    i18n_texts = []
    for key in texts:
        locale.setlocale(locale.LC_TIME, "{lang}{code}".format(lang=key,
                                                               code=".utf8"))
        value = texts[key].format(date=date_time.strftime(dates[key]),
                                  total_hours=hours_content[key],
                                  total_minutes=total_minutes)
        i18n_texts.append(i18n_text(key, value))

    locale.setlocale(locale.LC_TIME, "{lang}{code}".format(lang="en_US",
                                                           code=".utf8"))
    return make_text("Clock-out time has been registered. "
                     "The total working hours for {date} "
                     "is{total_hours}{total_minutes} minutes.".format(
                         date=date_time.strftime('%A, %B %d'),
                         total_hours=str_hours,
                         total_minutes=total_minutes),
                     i18n_texts=i18n_texts)
コード例 #2
0
def register_bot(photo_address):
    """
    Register a message bot.

        reference
        - https://developers.worksmobile.com/jp/document/1005002?lang=en

    :param photo_address: Access address of user's Avatar,
        If you need to change the user image,
        please replace the corresponding file in the image/, Only PNG file.
    :return: bot no
    """

    url = "https://" + DEVELOP_API_DOMAIN + "/r/" + API_ID + "/message/v1/bot"
    fmt = _("Attendance management bot")
    a = lambda x, y: {"language": x, "name": y}
    b = lambda x, y: {"language": x, "description": y}
    data = {
        "name": "Attendance management bot",
        "i18nNames": get_i18n_content(fmt, "registerBot", function=a),
        "photoUrl": photo_address,
        "description": "Attendance management bot",
        "i18nDescriptions": get_i18n_content(fmt, "registerBot", function=b),
        "managers": [ADMIN_ACCOUNT],
        "submanagers": [],
        "useGroupJoin": False,
        "useDomainScope": False,
        "useCallback": True,
        "callbackUrl": CALLBACK_ADDRESS,
        "callbackEvents": ["text", "location", "sticker", "image"]
    }

    r = requests.post(url, data=json.dumps(data), headers=headers())
    if r.status_code != 200:
        print(r.text)
        print(r.content)
        return None
    tmp = r.json()
    print(tmp)
    return tmp["botNo"]