Skip to content

Commit 585b483

Browse files
pylique now say what speaker is in track1, track2 or both and the next one
1 parent b291f99 commit 585b483

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

schedule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def create_card(speaker_info: object) -> object:
2626
"imageUri": BASE_URL + speaker_info['speakers'][0]['photo'],
2727
"buttons": [
2828
{
29-
"text": "prueba button"
29+
"text": f"{speaker_info['speakers'][0]['name']} {speaker_info['speakers'][0]['surname']}"
3030
}
3131
]
3232
},

tracks.py

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4+
import datetime
45
import requests
56
from parse_response import parse_response
67
BASE_URL = 'https://pythoncanarias.es'
@@ -26,26 +27,37 @@ def create_card(speaker_info: object) -> object:
2627
"imageUri": BASE_URL + speaker_info['speakers'][0]['photo'],
2728
"buttons": [
2829
{
29-
"text": "prueba button"
30+
"text": f"{speaker_info['speakers'][0]['name']} {speaker_info['speakers'][0]['surname']}"
3031
}
3132
]
3233
},
3334
'platform': 'TELEGRAM',
3435
}
3536

3637

37-
def create_tracks_cards(tracks_information: list, selected_track: int = None):
38+
def create_tracks_cards(tracks_information: list, selected_track: int = None, speaker_specific_hour: str = None) -> object:
3839
if selected_track == 1:
3940
track_one_information = tracks_information['result'][0]['schedule']
4041
track_one = []
4142
for track_info in track_one_information:
42-
track_one.append(create_card(track_info))
43+
print(track_info)
44+
if speaker_specific_hour:
45+
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'):
46+
track_one.append(create_card(track_info))
47+
break
48+
else:
49+
track_one.append(create_card(track_info))
4350
track_cards = track_one
4451
elif selected_track == 2:
4552
track_two_information = tracks_information['result'][1]['schedule']
4653
track_two = []
4754
for track_info in track_two_information:
48-
track_two.append(create_card(track_info))
55+
if speaker_specific_hour:
56+
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'):
57+
track_one.append(create_card(track_info))
58+
break
59+
else:
60+
track_two.append(create_card(track_info))
4961
track_cards = track_two
5062
else:
5163
tracks = []
@@ -82,16 +94,39 @@ def create_tracks_cards(tracks_information: list, selected_track: int = None):
8294
track_cards = tracks
8395
return track_cards
8496

97+
def get_speaker_specific_hour():
98+
return ''.join(str(datetime.datetime.now().hour) + ':' + str(datetime.datetime.now().minute))
99+
100+
101+
def get_next_speaker():
102+
return ''.join(str(datetime.datetime.now().hour + 1 ) + ':' + str(datetime.datetime.now().minute))
103+
85104

86105
def tracks_action(req: object = None) -> object:
87106
"""tracks action
88107
"""
89108
tracks_information = get_tracks_information()
90109
if req['queryResult']['parameters']['number']:
91110
selected_track = int(req['queryResult']['parameters']['number'])
92-
tracks_cards = create_tracks_cards(tracks_information, selected_track)
111+
if req['queryResult']['parameters']['now_entities']:
112+
speaker_specific_hour = get_speaker_specific_hour()
113+
tracks_cards = create_tracks_cards(tracks_information, selected_track, speaker_specific_hour)
114+
else:
115+
tracks_cards = create_tracks_cards(tracks_information, selected_track)
116+
if req['queryResult']['parameters']['next_entities']:
117+
speaker_specific_hour = get_next_speaker()
118+
tracks_cards = create_tracks_cards(tracks_information, selected_track, speaker_specific_hour)
93119
else:
94-
tracks_cards = create_tracks_cards(tracks_information)
120+
if req['queryResult']['parameters']['now_entities']:
121+
speaker_specific_hour = get_speaker_specific_hour()
122+
if req['queryResult']['parameters']['next_entities']:
123+
speaker_specific_hour = get_next_speaker()
124+
tracks_cards = create_tracks_cards(tracks_information, speaker_specific_hour)
125+
else:
126+
tracks_cards = create_tracks_cards(tracks_information)
127+
if req['queryResult']['parameters']['next_entities']:
128+
speaker_specific_hour = get_next_speaker()
129+
tracks_cards = create_tracks_cards(tracks_information, selected_track, speaker_specific_hour)
95130
result = {"fulfillmentMessages": []}
96131
for track_card in tracks_cards:
97132
result['fulfillmentMessages'].append(track_card)

0 commit comments

Comments
 (0)