Created
October 8, 2022 07:12
-
-
Save Lakshmi-1212/8df4380e07fc1246d2e493e506f33327 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 ActionGetRecentMatches(Action): | |
def name(self): | |
return 'action_get_recent_matches' | |
def run(self, dispatcher, tracker, domain): | |
res = requests.get(CRIC_API_URL + "currentMatches" + "?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) | |
matches_data = [x for x in matches_data if "matchType" in x] | |
recent_matches = matches_data[:SHOW_RECENT_MATCHES] | |
dispatcher.utter_message(f'Showing the status of {len(recent_matches)} recent matches\n') | |
for index, match in enumerate(recent_matches): | |
msg = f'{index+1}. {match["matchType"].upper()} match between ' \ | |
f'{match["teams"][0]} and {match["teams"][1]} played on {match["date"]}\n' \ | |
f'Match Status: {match["status"]}\n' | |
dispatcher.utter_message(msg) | |
else: | |
dispatcher.utter_message(f'Unable to fetch the recent matches details. Please try with some other query!!') | |
return [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment