Created
October 9, 2022 08:55
-
-
Save Lakshmi-1212/6aec47267163e11e97c874652cc87c93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActionGetUpcomingMatches(Action): | |
def name(self): | |
return 'action_get_upcoming_matches' | |
def run(self, dispatcher, tracker, domain): | |
res = requests.get(CRIC_API_URL + "matches" + "?apikey=" + CRIC_API_KEY + "&offset=0") | |
if res.status_code == 200: | |
matches_data = res.json()["data"] | |
matches_data.sort(key=lambda x: x["date"], reverse=True) | |
team_name = tracker.get_slot('team') | |
if team_name is None: | |
dispatcher.utter_message(f"Team not set. Showing the results for all the upcoming matches.") | |
team_name = "All Teams" | |
else: | |
matches_data = [x for x in matches_data if team_name in x["teams"]] | |
if len(matches_data): | |
dispatcher.utter_message(f'Showing the upcoming matches ({len(matches_data)}) for team: {team_name}\n') | |
for index, match in enumerate(matches_data): | |
msg = f'{index+1}. {match["matchType"].upper() if "matchType" in match else "A"} match between {match["teams"][0]} and {match["teams"][1]}. ' \ | |
f'Date: {match["date"]}, Venue: {match["venue"]}\n' | |
dispatcher.utter_message(msg) | |
else: | |
dispatcher.utter_message(f'No upcoming matches for team: {team_name}\n') | |
else: | |
dispatcher.utter_message(f'Unable to fetch the upcoming matches details. Please try with some other query!!') | |
return [SlotSet('team',None)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment