From b291f99c4ea92cb4d3209d78e4f37b5cf9be3207 Mon Sep 17 00:00:00 2001 From: PedroRamosRguez Date: Wed, 6 Nov 2019 19:44:54 +0000 Subject: [PATCH 1/2] bot now show a help commands --- app.py | 2 ++ help.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 help.py diff --git a/app.py b/app.py index d99257e..5dd471d 100644 --- a/app.py +++ b/app.py @@ -4,6 +4,7 @@ import os from flask import Flask from flask import request +from help import help_action from welcome import welcome_action from schedule import schedule_action from sponsors import sponsors_action @@ -13,6 +14,7 @@ log = app.logger actions = { + 'help': help_action, 'welcome': welcome_action, 'schedule': schedule_action, 'sponsors': sponsors_action, diff --git a/help.py b/help.py new file mode 100644 index 0000000..c09daeb --- /dev/null +++ b/help.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +from parse_response import parse_response + + +def commands(): + return ''.join( + '/track1 \n' + '/track2 \n' + '/agenda \n' + '/ponencias \n' + '/ponentes \n' + '/ayuda \n' + '/command \n' + '/commands \n' + ) + + +def help_action(req: object = None) -> object: + """help action + """ + command_list = commands() + result = { + "fulfillmentMessages": [ + { + "payload": { + "telegram": { + "text": f"""Estos son algunos de los comandos que puedes utilizar. \n\n {command_list}\n\n Además, puedes hablar con el bot sin necesidad de solo utilizar comandos. Ej: ponencias del pyday""", + "parse_mode": "Markdown" + } + }, + "platform": "TELEGRAM", + }, + ], + } + response = parse_response(result) + return response From 585b483732516d405a12f0b0dd0b196456bd3db2 Mon Sep 17 00:00:00 2001 From: PedroRamosRguez Date: Wed, 6 Nov 2019 20:07:39 +0000 Subject: [PATCH 2/2] pylique now say what speaker is in track1, track2 or both and the next one --- schedule.py | 2 +- tracks.py | 47 +++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/schedule.py b/schedule.py index 975a143..1c1dbd9 100644 --- a/schedule.py +++ b/schedule.py @@ -26,7 +26,7 @@ def create_card(speaker_info: object) -> object: "imageUri": BASE_URL + speaker_info['speakers'][0]['photo'], "buttons": [ { - "text": "prueba button" + "text": f"{speaker_info['speakers'][0]['name']} {speaker_info['speakers'][0]['surname']}" } ] }, diff --git a/tracks.py b/tracks.py index 57d55ec..001e8bd 100644 --- a/tracks.py +++ b/tracks.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +import datetime import requests from parse_response import parse_response BASE_URL = 'https://pythoncanarias.es' @@ -26,7 +27,7 @@ def create_card(speaker_info: object) -> object: "imageUri": BASE_URL + speaker_info['speakers'][0]['photo'], "buttons": [ { - "text": "prueba button" + "text": f"{speaker_info['speakers'][0]['name']} {speaker_info['speakers'][0]['surname']}" } ] }, @@ -34,18 +35,29 @@ def create_card(speaker_info: object) -> object: } -def create_tracks_cards(tracks_information: list, selected_track: int = None): +def create_tracks_cards(tracks_information: list, selected_track: int = None, speaker_specific_hour: str = None) -> object: if selected_track == 1: track_one_information = tracks_information['result'][0]['schedule'] track_one = [] for track_info in track_one_information: - track_one.append(create_card(track_info)) + print(track_info) + if speaker_specific_hour: + if datetime.datetime.strptime(speaker_specific_hour,'%H:%M') >= datetime.datetime.strptime(track_info['start'],'%H:%M') and datetime.datetime.strptime(speaker_specific_hour, '%H:%M') <= datetime.datetime.strptime(track_info['end'], '%H:%M'): + track_one.append(create_card(track_info)) + break + else: + track_one.append(create_card(track_info)) track_cards = track_one elif selected_track == 2: track_two_information = tracks_information['result'][1]['schedule'] track_two = [] for track_info in track_two_information: - track_two.append(create_card(track_info)) + if speaker_specific_hour: + if datetime.datetime.strptime(speaker_specific_hour,'%H:%M') >= datetime.datetime.strptime(track_info['start'],'%H:%M') and datetime.datetime.strptime(speaker_specific_hour, '%H:%M') <= datetime.datetime.strptime(track_info['end'], '%H:%M'): + track_one.append(create_card(track_info)) + break + else: + track_two.append(create_card(track_info)) track_cards = track_two else: tracks = [] @@ -82,6 +94,13 @@ def create_tracks_cards(tracks_information: list, selected_track: int = None): track_cards = tracks return track_cards +def get_speaker_specific_hour(): + return ''.join(str(datetime.datetime.now().hour) + ':' + str(datetime.datetime.now().minute)) + + +def get_next_speaker(): + return ''.join(str(datetime.datetime.now().hour + 1 ) + ':' + str(datetime.datetime.now().minute)) + def tracks_action(req: object = None) -> object: """tracks action @@ -89,9 +108,25 @@ def tracks_action(req: object = None) -> object: tracks_information = get_tracks_information() if req['queryResult']['parameters']['number']: selected_track = int(req['queryResult']['parameters']['number']) - tracks_cards = create_tracks_cards(tracks_information, selected_track) + if req['queryResult']['parameters']['now_entities']: + speaker_specific_hour = get_speaker_specific_hour() + tracks_cards = create_tracks_cards(tracks_information, selected_track, speaker_specific_hour) + else: + tracks_cards = create_tracks_cards(tracks_information, selected_track) + if req['queryResult']['parameters']['next_entities']: + speaker_specific_hour = get_next_speaker() + tracks_cards = create_tracks_cards(tracks_information, selected_track, speaker_specific_hour) else: - tracks_cards = create_tracks_cards(tracks_information) + if req['queryResult']['parameters']['now_entities']: + speaker_specific_hour = get_speaker_specific_hour() + if req['queryResult']['parameters']['next_entities']: + speaker_specific_hour = get_next_speaker() + tracks_cards = create_tracks_cards(tracks_information, speaker_specific_hour) + else: + tracks_cards = create_tracks_cards(tracks_information) + if req['queryResult']['parameters']['next_entities']: + speaker_specific_hour = get_next_speaker() + tracks_cards = create_tracks_cards(tracks_information, selected_track, speaker_specific_hour) result = {"fulfillmentMessages": []} for track_card in tracks_cards: result['fulfillmentMessages'].append(track_card)