Skip to content

Instantly share code, notes, and snippets.

@mohdsanadzakirizvi
Last active November 19, 2019 08:48
Show Gist options
  • Save mohdsanadzakirizvi/e30d9df9cd1fcce0cd0d10e4266e7452 to your computer and use it in GitHub Desktop.
Save mohdsanadzakirizvi/e30d9df9cd1fcce0cd0d10e4266e7452 to your computer and use it in GitHub Desktop.
API_URL = "https://cricapi.com/api/"
API_KEY = ""
class ApiAction(Action):
def name(self):
return "action_match_news"
def run(self, dispatcher, tracker, domain):
res = requests.get(API_URL + "matches" + "?apikey=" + API_KEY)
if res.status_code == 200:
data = res.json()["matches"]
recent_match = data[0]
upcoming_match = data[1]
upcoming_match["date"] = datetime.strptime(upcoming_match["date"], "%Y-%m-%dT%H:%M:%S.%fZ")
next_date = upcoming_match["date"].strftime("%d %B %Y")
out_message = "Here some IPL quick info:\n1.The match between {} and {} was recently held and {} won.".format(recent_match["team-1"], recent_match["team-2"], recent_match["winner_team"])
dispatcher.utter_message(out_message)
out_message = "2.The next match is {} vs {} on {}".format(upcoming_match["team-1"], upcoming_match["team-2"], next_date)
dispatcher.utter_message(out_message)
return []
Me: Hi
Iplbot: Hey! How may I help you?
Me: What was the result of the last match?
Iplbot: Here are some IPL quick info:
1.The match between Rajasthan Royals and Delhi Capitals was recently held and Delhi Capitals won.
2.The next match is Warriors vs Titans on 22 April 2019
Iplbot: Did that help you?
Me: yes, thank you!
Iplbot: Glad that I could help! :)
{
'intent': {
'name': 'current_matches',
'confidence': 0.6657130383645372
},
'entities': [],
'intent_ranking': [{
'name': 'current_matches',
'confidence': 0.6657130383645372
}, {
'name': 'goodbye',
'confidence': 0.11589267701634796
}, {
'name': 'affirm',
'confidence': 0.06372593552204527
}, {
'name': 'thanks',
'confidence': 0.0623182164883462
}, {
'name': 'deny',
'confidence': 0.05938353524001583
}, {
'name': 'greet',
'confidence': 0.03296659736870796
}],
'text': 'what is happening in the cricket world these days?'
}
## intent:current_matches
- which cricket match is happening right now
- which ipl match is next
- which teams are playing next in ipl
- tell me some ipl news
- i want ipl updates
- what are the latest match updates
- who won the last ipl match
- how is ipl going
- what was the result of the last match
- when is the next match
policies:
- name: KerasPolicy
epochs: 100
max_history: 5
- name: FallbackPolicy
fallback_action_name: 'action_default_fallback'
- name: MemoizationPolicy
max_history: 5
Me: Hi
Iplbot: Hey! How may I help you?
Me: What was the result of the last match?
Iplbot: Here are some IPL quick info:
1.The match between Rajasthan Royals and Delhi Capitals was recently held and Delhi Capitals won.
2.The next match is Warriors vs Titans on 22 April 2019
Iplbot: Did that help you?
Me: yes, thank you!
Iplbot: Glad that I could help! 🙂
## news path 1
* greet
- utter_greet
* current_matches
- action_match_news
- utter_did_that_help
* affirm or thanks
- utter_gratitude
* goodbye
- utter_goodbye
## news path 1
* greet
- utter_greet
* current_matches
- action_match_news
- utter_did_that_help
* affirm or thanks
- utter_gratitude
* goodbye
- utter_goodbye
## news path 2
* current_matches
- action_match_news
- utter_did_that_help
* affirm or thanks
- utter_gratitude
* goodbye
- utter_goodbye
## news path 3
* greet
- utter_greet
* current_matches
- action_match_news
- utter_did_that_help
* deny
- utter_ask_again
* current_matches
- action_match_news
- utter_did_that_help
* affirm or thanks
- utter_gratitude
* goodbye
- utter_goodbye
## greet path
* greet
- utter_greet
## goodbye path
* goodbye
- utter_goodbye
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment