Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue#3 #5

Merged
merged 2 commits into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,6 +14,7 @@
log = app.logger

actions = {
'help': help_action,
'welcome': welcome_action,
'schedule': schedule_action,
'sponsors': sponsors_action,
Expand Down
38 changes: 38 additions & 0 deletions help.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']}"
}
]
},
Expand Down
47 changes: 41 additions & 6 deletions tracks.py
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -26,26 +27,37 @@ 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']}"
}
]
},
'platform': 'TELEGRAM',
}


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 = []
Expand Down Expand Up @@ -82,16 +94,39 @@ 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
"""
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)
Expand Down