Skip to content

Added new feature of Cricket #393

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions local/wit.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@
"test": {
"intent": "xkcd",
"entities": []
},
"cricket": {
"intent": "cricket",
"entities": []
}
}
5 changes: 5 additions & 0 deletions messenger/persistent_menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
"title": "videos of sia",
"payload": "{\"entities\": {\"video\":[{\"value\":\"sia\"}]}, \"intent\": \"video\"}"
}
{
"type": "postback",
"title": "cricket livescores",
"payload": "{\"entities\": null, \"intent\": \"cricket\"}"
}
]
},
{
Expand Down
1 change: 1 addition & 0 deletions modules/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'book',
'bye',
'coin',
'cricket',
'currency',
'dice',
'dictionary',
Expand Down
33 changes: 33 additions & 0 deletions modules/src/cricket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from pycricbuzz import Cricbuzz
import requests
import requests_cache
from templates.button import *


def process(input, entities=None):
output = {}
try:
cricket = Cricbuzz()
matches = cricket.matches()
text_data=""
template = TextTemplate()
for match in matches:
cric_data=cricket.livescore(match['id'])
text_data+=cric_data['matchinfo']['mnum']+"\n"+cric_data['matchinfo']['mchdesc']+"\n"
if "Starts" not in cric_data['matchinfo']['status']:
text_data+=cric_data['batting']['team']+"\t"+cric_data['batting']['score'][0]['runs']+"/"+cric_data['batting']['score'][0]['wickets']+"\n"
text_data+=cric_data['bowling']['team']+"\t"+cric_data['bowling']['score'][0]['runs']+"/"+cric_data['bowling']['score'][0]['wickets']+"\n"
text_data+=cric_data['matchinfo']['status']+"\n"+"*"*10+"\n"
template.set_text(text_data)
text = template.get_text()
template = ButtonTemplate(text)
template.add_web_url('CricBuzz Live', 'http://www.cricbuzz.com/cricket-match/live-scores')

output['input'] = input
output['output'] = template.get_message()
output['success'] = True
except:
error_message = 'There was some error while retrieving data from Cricbuzz'
output['error_msg'] = TextTemplate(error_message).get_message()
output['success'] = False
return output
8 changes: 8 additions & 0 deletions modules/tests/test_cricket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import modules

def test_cricket():
assert ('cricket' == modules.process_query('cricket')[0])
assert ('cricket' == modules.process_query('live cricket')[0])
assert ('cricket' == modules.process_query('cricket livescores')[0])
assert ('cricket' != modules.process_query('something random')[0])

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pbr==3.1.1
py==1.4.34
pyasn1==0.1.9
pycparser==2.14
pycricbuzz==0.8
pycryptodome==3.4.7
PyDispatcher==2.0.5
pyOpenSSL==16.0.0
Expand Down