Ejemplo n.º 1
0
def eventupdate(request):
    google_calendar = get_credential(request)
    data = [l.strip() for l in request['text'].split(',') if l.strip()]

    if len(data) == 3:
        b = google_calendar.update_Calendar(calendar_name=data[0],
                                            previous_text=data[1],
                                            update_summary=data[2])
    elif len(data) == 5:
        b = google_calendar.update_Calendar(calendar_name=data[0],
                                            previous_text=data[1],
                                            update_summary=data[2],
                                            sndate=[data[3], data[4]])
    else:
        b = False

    if type(b) == bool:

        if request['platform'] is Telegram.platform():
            result = "*calender update*\n\n"
            result = result + data[1] + ' 에서 ' + data[
                2] + '로' + ' 이벤트 수정에 ' + tf[b]
            slashResponse = SlashResponse(result)

        else:
            slashResponse = SlashResponse({
                'attachments': [{
                    'pretext':
                    '이벤트 수정',
                    'text':
                    data[1] + ' 에서 ' + data[2] + '로' + ' 이벤트 수정에 ' + tf[b],
                    'color':
                    '#7CD197',
                }]
            })
    else:
        if b == 4000:
            b = "Error: 캘린더 이름을 확인해주세요."
        elif b == 5000:
            b = "Error: 입력을 다시 확인해주세요."

        if request['platform'] is Telegram.platform():
            result = "*calender update*\n\n"
            result = result + b
            slashResponse = SlashResponse(result)
        else:
            slashResponse = SlashResponse({
                'attachments': [{
                    'pretext': '이벤트 수정',
                    'text': b,
                    'color': '#7CD197',
                }]
            })

    return slashResponse
Ejemplo n.º 2
0
def eventlist(request):
    google_calendar = get_credential(request)
    data = [l.strip() for l in request['text'].split(',') if l.strip()]
    if len(data) == 2:
        data[1] = int(float(data[1]))
        b = google_calendar.list_Calendar(calendar_name=data[0],
                                          maxResult=data[1])
    elif len(data) == 1:
        b = google_calendar.list_Calendar(calendar_name=data[0])
    else:
        b = ["Error: 입력을 확인해주세요"]

    if b.__class__ == int:
        if b == 4000:
            b = 'Error: 캘린더 이름을 확인해 주세요'
    else:
        b = '\r\n'.join(b).strip()
        if not b.strip():
            b = '출력할 데이터가 없습니다'
    if request['platform'] is Telegram.platform():
        result = "*이벤트 리스트*\n\n"
        result = result + b
        slashResponse = SlashResponse(result)
    else:
        slashResponse = SlashResponse({
            'attachments': [{
                'pretext': '이벤트 리스트',
                'text': b,
                'color': '#7CD197',
            }]
        })
    return slashResponse
Ejemplo n.º 3
0
def webhook(request):
    print('get telegram message!!')
    telegram_body = request.body
    json_list = json.loads(telegram_body)
    json_list['chat_platform_type'] = 'telegram'
    request.POST = json_list

    slash_command = None
    print(json_list)
    slash_command, _ = Telegram.cutCommand(json_list)

    print('slected slash command ', slash_command)
    if slash_command is None:
        print('invalid data from telegram: ', telegram_body)
        return HttpResponse()

    # TODO 예외처리
    print('slash command :', slash_command)
    urls = get_resolver(None).reverse_dict
    if slash_command not in urls:
        print('invalid command from telegram: ', slash_command)
        return HttpResponse()

    path = '/' + urls[slash_command][1].replace('\\', '')[:-1]
    print(path)
    func, _, _ = resolve(path)

    return func(request)
Ejemplo n.º 4
0
def eventinsert(request):
    google_calendar = get_credential(request)
    data = [l.strip() for l in request['text'].split(',') if l.strip()]

    if len(data) == 4:
        b = google_calendar.insert_Calendar(calendar_name=data[0],
                                            text=data[1],
                                            start=data[2],
                                            end=data[3])
    else:
        data.append('Null')
        b = False

    if type(b) == bool:
        if request['platform'] is Telegram.platform():
            result = "*calender Insert*\n\n"
            result = result + data[1] + "이벤트 추가에 " + tf[b]
            slashResponse = SlashResponse(result)
        else:
            slashResponse = SlashResponse({
                'attachments': [{
                    'pretext': '이벤트 추가',
                    'text': data[1] + ' 이벤트 추가에 ' + tf[b],
                    'color': '#7CD197',
                }]
            })
    else:
        if b == 4000:
            b = "Error: 캘린더 이름을 확인해주세요."
        elif b == 5000:
            b = "Error: 날짜 입력을 확인해주세요."

        if request['platform'] is Telegram.platform():
            result = "*calender Insert*\n\n"
            result = result + b
            slashResponse = SlashResponse(result)
        else:
            slashResponse = SlashResponse({
                'attachments': [{
                    'pretext': '이벤트 추가',
                    'text': b,
                    'color': '#7CD197',
                }]
            })
    return slashResponse
Ejemplo n.º 5
0
def eventdelete(request):
    google_calendar = get_credential(request)
    data = [l.strip() for l in request['text'].split(',') if l.strip()]

    if len(data) != 2:
        b = False
    else:
        b = google_calendar.delete_Calendar(calendar_name=data[0],
                                            text=data[1])

    if type(b) == bool:

        if request['platform'] is Telegram.platform():
            result = "*calender delete*\n\n"
            result = result + data[1] + '이벤트 삭제에 ' + tf[b]
            slashResponse = SlashResponse(result)
        else:
            slashResponse = SlashResponse({
                'attachments': [{
                    'pretext': '이벤트 삭제',
                    'text': data[1] + ' 이벤트 삭제에 ' + tf[b],
                    'color': '#7CD197',
                }]
            })
    else:
        if b == 4000:
            b = "Error: 캘린더 이름을 확인해주세요."
        elif b == 5000:
            b = "Error: 이벤트 Text를 확인해주세요."

        if request['platform'] is Telegram.platform():
            result = "*calender delete*\n\n"
            result = result + b
            slashResponse = SlashResponse(result)
        else:
            slashResponse = SlashResponse({
                'attachments': [{
                    'pretext': '이벤트 삭제',
                    'text': b,
                    'color': '#7CD197',
                }]
            })
    return slashResponse
Ejemplo n.º 6
0
    def delay_message():
        time.sleep(delay_time)
        send_message = user_name + ">님이 예약한 메시지_\n\n" + message

        if platform is Telegram.platform():
            send_message = "_<" + send_message
        else:
            send_message = "_<@" + user_id + "|" + send_message

        return SlashResponse(send_message)
Ejemplo n.º 7
0
def lunch(request):
    text = request['text']
    respon = crowling.crowlier_lunch(text)
    respon1 = list(zip(respon[0], respon[1]))
    list1 = []

    if request['platform'] is Telegram.platform():
        for (first, last) in respon1:
            list1.append(first)
            list1.append("주소 : " + last)

        test = str(list1)
        count = 0
        number = 0
        list_str = []

        for mark in test:
            if test[number] == ',':
                count = count + 1
            if count == 3:
                if test[number] == ',':
                    list_str.append('\n')
            if count == 4:
                if test[number] == ',':
                    list_str.append('\n')
                    count = 0
            else:
                list_str.append(test[number])
            number = number + 1

        test = "".join(list_str)
        test = str(test)

        result = "*맛집 결과?*\n\n"
        result = result + test
        slashResponse = SlashResponse(result)

    else:

        for (first, last) in respon1:
            list1.append({'title': first, 'value': last, 'short': True})

        slashResponse = SlashResponse({
            "attachments": [{
                "title": text + " 맛집입니다.",
                "fields": list1,
                "color": "#F35A00",
            }]
        })
    return slashResponse
Ejemplo n.º 8
0
def calendarlist(request):
    google_calendar = get_credential(request)
    calendarList = '\r\n'.join(google_calendar.get_Calendar())
    if request['platform'] is Telegram.platform():
        result = "*calender list*\n\n"
        result = result + calendarList
        print(calendarList)
        slashResponse = SlashResponse(result)
    else:
        slashResponse = SlashResponse({
            'attachments': [{
                'pretext': '캘린더 리스트',
                'text': calendarList,
                'color': '#7CD197',
            }]
        })
    return slashResponse
Ejemplo n.º 9
0
def help(request):
    google_calendar = get_credential(request)
    text = google_calendar.help()
    if request['platform'] is Telegram.platform():
        result = "*calender help*\n\n"
        result = result + text.replace('-', '\_')
        print(result)
        slashResponse = SlashResponse(result)
    else:
        slashResponse = SlashResponse({
            'attachments': [{
                'pretext': '도움말',
                'text': text,
                'color': '#7CD197',
            }]
        })

    return slashResponse
Ejemplo n.º 10
0
def lunch_category(request):
    text = request['text']
    respon = crowling.lunch_category()

    list1 = []

    if request['platform'] is Telegram.platform():
        for first in respon:
            if first != '전체보기':
                list1.append(" " + first + " ")

        test = str(list1)
        count = 0
        number = 0
        list_str = []

        for mark in test:
            if test[number] == ',':
                list_str.append('\n')
            else:
                list_str.append(test[number])
            number = number + 1

        test = "".join(list_str)
        test = str(test)

        result = "*맛집 카테고리*\n\n"
        result = result + test
        print(result)
        slashResponse = SlashResponse(result)
        return slashResponse
    else:

        for first in respon:
            list1.append({'title': first, 'short': True})
        return SlashResponse({
            "attachments": [{
                "title": "맛집 카테고리입니다",
                "fields": list1,
                "color": "#F35A00",
            }]
        })