Exemplo n.º 1
0
def command_new(event, line_bot_api, **kwargs):
    logger = logging.getLogger(__name__)

    match = kwargs['match']
    golf_club = kwargs['golf_club']
    membership = kwargs['membership']

    # New "John Doe" 2020-08-10 12:30 3 GOLFER 3 CART

    # 1. Check if N unpaid booking exist
    if (count := golf_models.GolfBookingOrder.objects
            .filter(golf_club=golf_club,
                    line_user=membership.line_user,
                    order_status__in=[golf_models.GolfBookingOrder.ORDER_STATUS_CHOICES.open,
                                      golf_models.GolfBookingOrder.ORDER_STATUS_CHOICES.offered,
                                      golf_models.GolfBookingOrder.ORDER_STATUS_CHOICES.accepted,
                                      golf_models.GolfBookingOrder.ORDER_STATUS_CHOICES.confirmed],
                    payment_status=golf_models.GolfBookingOrder.PAYMENT_STATUS_CHOICES.unpaid,
                    invisible=False)
            .count()) >= golf_club.multiple_booking_orders:
        line_bot_api.reply_message(
            event.reply_token,
            models.TextSendMessage(
                text=_('You cannot make a new booking because you already have the unpaid {} booking orders')
                    .format(count)))
        return
Exemplo n.º 2
0
        def handle_post_back(event):
            qs = dict(parse_qsl(event.postback.data))

            cache_key = f'chatbot.membership({event.source.user_id},{golf_club.id})'

            membership = cache.get(cache_key)

            # Retrieve LINE user
            if not membership:
                try:
                    membership = golf_models.LineUserMembership.objects \
                        .select_related('line_user', 'customer_group') \
                        .get(line_user__line_user_id=event.source.user_id,
                             customer_group__golf_club=golf_club)
                    cache.set(cache_key, membership, cache_time)
                except golf_models.LineUserMembership.DoesNotExist:
                    self.line_bot_api.reply_message(
                        event.reply_token,
                        models.TextSendMessage(text='Invalid Golf Course or LINE ID'))
                    return

            if qs['action'] == 'accept':
                post_back.command_accept(event, self.line_bot_api, qs=qs, golf_club=golf_club, membership=membership)
            elif qs['action'] == 'close':
                post_back.command_close(event, self.line_bot_api, qs=qs, golf_club=golf_club, membership=membership)
Exemplo n.º 3
0
def command_settings(event, line_bot_api, **kwargs):
    match = kwargs['match']
    golf_club = kwargs['golf_club']
    membership = kwargs['membership']

    membership.line_user.fullname = match[1]
    membership.line_user.email = match[2]
    membership.line_user.phone = match[3]
    membership.line_user.lang = match[4]
    membership.line_user.save()

    cache.delete(f'chatbot.membership({event.source.user_id},{golf_club.id})')

    line_bot_api.link_rich_menu_to_user(membership.line_user.line_user_id, golf_club.line_rich_menu[match[4]])

    translation.activate(match[4])

    line_bot_api.reply_message(
        event.reply_token, [
            models.TextSendMessage(text=_('''Your profile has been saved.
Customer name: {}
Email: {}
Telephone: {}
Language: {}''').format(match[1], match[2], match[3], match[4]))])

    translation.deactivate()
Exemplo n.º 4
0
def command_accept(event, line_bot_api, **kwargs):
    qs = kwargs['qs']

    tee_time = timezone.datetime.strptime(qs['tee_time'], '%H:%M').time()

    order = golf_models.GolfBookingOrder.objects.get(order_no=qs['order_no'])
    order.order_status = golf_models.GolfBookingOrder.ORDER_STATUS_CHOICES.accepted
    order.round_time = tee_time
    order.save()

    round_date_formatted = date(order.round_date, 'Y-m-d')
    round_time_formatted = date(tee_time, 'H:i')

    golf_utils.log_order_status(
        None, order,
        golf_models.GolfBookingOrder.ORDER_STATUS_CHOICES.accepted,
        order.payment_status,
        f'{round_date_formatted} [{round_time_formatted}]\n'
        f'{order.pax} PAX {order.cart} CART\n')

    line_bot_api.reply_message(
        event.reply_token,
        models.TextSendMessage(
            text=
            f'You accepted our offer: {round_date_formatted} {round_time_formatted}\n\n'
            'We will send you the confirmation notification in a few minutes.\n\n'
            'Thank you.'))
Exemplo n.º 5
0
        def handle_message(event):
            text = event.message.text.strip()
            text_lowercase = text.lower()

            cache_key = f'chatbot.membership({event.source.user_id},{golf_club.id})'

            membership = cache.get(cache_key)

            # Retrieve LINE user
            if not membership:
                try:
                    membership = golf_models.LineUserMembership.objects \
                        .select_related('line_user', 'customer_group') \
                        .get(line_user__line_user_id=event.source.user_id,
                             customer_group__golf_club=golf_club)
                    cache.set(cache_key, membership, cache_time)
                except golf_models.LineUserMembership.DoesNotExist:
                    self.line_bot_api.reply_message(
                        event.reply_token,
                        models.TextSendMessage(text='Invalid Golf Course or LINE ID'))
                    return

            if match := re \
                    .compile('New\s"(.+)"\s(\d\d\d\d-\d\d-\d\d)\s(\d\d:\d\d)\s(\d)\sGOLFER\s(\d)\sCART', re.I) \
                    .match(text):
                message.command_new(event, self.line_bot_api, match=match,
                                    golf_club=golf_club, membership=membership)
Exemplo n.º 6
0
def handle_message(event):

    # nippon.comのwebサイトから日本国内の感染者情報を取得
    ip = infected_person.NipponComSite()
    hit_word = ip.searcher(event.message.text)
    if not hit_word:
        hit_word = text

    line_bot_api.reply_message(event.reply_token,
                               models.TextSendMessage(text=hit_word))
Exemplo n.º 7
0
 def handle(self, *args, **options):
     iottalk = dan.Iottalk(
         dm_name="Dummy_Device",
         df_list=["Dummy_Control"],
         d_name="rollcall-notifier",
         mac=uuid.uuid4().hex,
     )
     iottalk.device_registration_with_retry(os.getenv("IOTTALK_ENDPOINT"))
     line_api = linebot.LineBotApi(os.getenv("LINE_ACCESS_TOKEN"))
     try:
         while True:
             data = iottalk.pull("Dummy_Control")
             if data:
                 line_api.broadcast(models.TextSendMessage(data[0]))
             time.sleep(0.2)
     finally:
         iottalk.deregister()
Exemplo n.º 8
0
def send_push_text_message_line(line_bot_channel_access_token, to, message,
                                **kwargs):
    quick_reply = None

    if 'postback_actions' in kwargs:
        items = []
        for action in kwargs['postback_actions']:
            items.append(
                models.QuickReplyButton(action=models.PostbackAction(
                    label=action['label'],
                    data=action['data'],
                    display_text=action['display_text'])))

        quick_reply = models.QuickReply(items=items)

    line_bot_api = linebot.LineBotApi(line_bot_channel_access_token)
    line_bot_api.push_message(
        to, models.TextSendMessage(text=message, quick_reply=quick_reply))
Exemplo n.º 9
0
def command_close(event, line_bot_api, **kwargs):
    qs = kwargs['qs']

    order = golf_models.GolfBookingOrder.objects.get(order_no=qs['order_no'])
    order.order_status = golf_models.GolfBookingOrder.ORDER_STATUS_CHOICES.closed
    order.save()

    round_date_formatted = date(order.round_date, 'Y-m-d')
    round_time_formatted = date(order.round_time, 'H:i')

    golf_utils.log_order_status(
        None, order, golf_models.GolfBookingOrder.ORDER_STATUS_CHOICES.closed,
        order.payment_status,
        f'{round_date_formatted} [{round_time_formatted}]\n'
        f'{order.pax} PAX {order.cart} CART\n')

    line_bot_api.reply_message(
        event.reply_token,
        models.TextSendMessage(
            text='You closed your booking.\n\n'
            'Please, make a new booking with another round date/time.\n\n'
            'Thank you.'))
Exemplo n.º 10
0
 def handle_member_joined(event):
     self.line_bot_api.reply_message(
         event.reply_token,
         models.TextSendMessage(text=f'Got memberJoined event. event={event}')
     )
Exemplo n.º 11
0
UserID = 'Your_UserID'

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome = webdriver.Chrome(options=chrome_options)

chrome.get("https://airtw.epa.gov.tw/")
time.sleep(3)

selectCounty = Select(chrome.find_element_by_id('ddl_county'))
selectCounty.select_by_index(1)
time.sleep(1)
selectSite = Select(chrome.find_element_by_id('ddl_site'))
selectSite.select_by_index(4)
time.sleep(4)

soup = BeautifulSoup(chrome.page_source, "html.parser")
air_info = soup.find_all('div', class_= 'info')[0]
state = air_info.find('h4').text[:6]
date = air_info.find('div', class_= 'date').text.strip()[:16]
PM25 = int(air_info.find('span', id = 'PM25').text)
if PM25<16:
    air_quality = "Good" + " PM2.5 - " + str(PM25)
elif PM25<35:
    air_quality = "Moderate" + " PM2.5 - " + str(PM25)
else:
    air_quality = "Unhealthy" + " PM2.5 - " + str(PM25)
    
text_message = models.TextSendMessage(text = str(date) + str(state) + str(air_quality))
line_bot_api.push_message(UserID, text_message)
Exemplo n.º 12
0
def command_restaurants(event, line_bot_api, **kwargs):
    line_bot_api.reply_message(
        event.reply_token,
        models.TextSendMessage(text='restaurants - carousel message'))
Exemplo n.º 13
0
def command_caddies(event, line_bot_api, **kwargs):
    line_bot_api.reply_message(
        event.reply_token,
        models.TextSendMessage(text='caddies - carousel message'))
Exemplo n.º 14
0
                message.command_caddies(event, self.line_bot_api, golf_club=golf_club, membership=membership)
            elif text_lowercase == 'layout':
                layout = self.request.build_absolute_uri(f'{golf_club.layout.url}')
                message.command_layout(event, self.line_bot_api, layout=layout,
                                       golf_club=golf_club, membership=membership)
            elif text_lowercase in ['hotels', 'hotel', 'accommodation', 'accommodations']:
                message.command_hotels(event, self.line_bot_api, golf_club=golf_club, membership=membership)
            elif text_lowercase in ['restaurants', 'restaurant', 'food']:
                message.command_restaurants(event, self.line_bot_api, golf_club=golf_club, membership=membership)
            else:
                self.line_bot_api.reply_message(
                    event.reply_token,
                    models.TextSendMessage(
                        text='What do you want to do?',
                        quick_reply=models.QuickReply(
                            items=[
                                models.QuickReplyButton(action=models.MessageAction(label='My Booking',
                                                                                    text='Booking')),
                            ])))

        @self.handler.add(models.PostbackEvent)
        def handle_post_back(event):
            qs = dict(parse_qsl(event.postback.data))

            cache_key = f'chatbot.membership({event.source.user_id},{golf_club.id})'

            membership = cache.get(cache_key)

            # Retrieve LINE user
            if not membership:
                try:
Exemplo n.º 15
0
                    payment_status=golf_models.GolfBookingOrder.PAYMENT_STATUS_CHOICES.unpaid,
                    invisible=False)
            .count()) >= golf_club.multiple_booking_orders:
        line_bot_api.reply_message(
            event.reply_token,
            models.TextSendMessage(
                text=_('You cannot make a new booking because you already have the unpaid {} booking orders')
                    .format(count)))
        return

    # 2. Message data validation
    # 2.1 match[4] PAX
    if not validators.validate_pax(pax := int(match[4]), golf_club=golf_club):
        line_bot_api.reply_message(
            event.reply_token,
            models.TextSendMessage(text=_('Invalid Golfer#: {} to {}').format(golf_club.min_pax, golf_club.max_pax)))
        return

    # 2.2. match[5] CART
    if not validators.validate_cart(cart := int(match[5]), pax, golf_club=golf_club):
        error_message = _('Invalid Cart#')

        if golf_club.cart_compulsory == 1:
            error_message = _('Invalid Cart#: Cart required')
        elif golf_club.cart_compulsory > 1:
            if pax >= golf_club.cart_compulsory:
                error_message = _('Invalid Cart#: Cart required {}+ Golfer').format(golf_club.cart_compulsory)
            else:
                error_message = _('Invalid Cart#')

        line_bot_api.reply_message(
Exemplo n.º 16
0
 def handle_join(event):
     # event.source.user_id mark as joined
     self.line_bot_api.reply_message(
         event.reply_token,
         models.TextSendMessage(text=f'Joined this {event.source.type}')
     )
Exemplo n.º 17
0
def handle_message(event):
    line_bot_api.reply_message(event.reply_token, models.TextSendMessage(text=event.message.text))