Skip to content

Instantly share code, notes, and snippets.

@nins-k
Created March 29, 2015 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nins-k/f1e9047709fbda4a8a5e to your computer and use it in GitHub Desktop.
Save nins-k/f1e9047709fbda4a8a5e to your computer and use it in GitHub Desktop.
Cricket module for Jenni IRC bot
"""
Cricket score script for Jenni IRC bot by NiNs
"""
import requests
import json
from bs4 import BeautifulSoup as BS
def getmatchID(team):
r = requests.get("http://cricscore-api.appspot.com/csa")
matches = json.loads(r.text.encode('utf-8'))
print(type(matches))
for match in matches:
print(type(match))
print(match)
if match['t1'].find(team)!=-1 or match['t2'].find(team)!=-1:
return match['id']
return None
def getmatchinfo(mid):
r = requests.get("http://cricscore-api.appspot.com/csa?id=" + str(mid))
info = json.loads(r.text.encode('utf-8'))
return info[0]
"""
More info but unreliable. Seems to be working more often lately.
"""
def cricinfo(jenni, input):
team = input.group(2)
if team is None:
jenni.reply("Enter the name of a team.")
return
team = team.title()
print(team)
print((len(team)))
mid = getmatchID(team)
if mid is None:
jenni.reply("Lol, idk.")
else:
info = getmatchinfo(mid)
jenni.say(info['si'] + " | " + info['de'])
cricinfo.commands = ['cric2']
cricinfo.prority = 'medium'
"""
Basic info but completely reliable.
"""
def cricxml(jenni, input):
team = input.group(2)
r = requests.get("http://static.cricinfo.com/rss/livescores.xml")
bs = BS(r.text)
matches = bs.find_all('item')
if team is None:
jenni.reply("Pvt-ing info on all available matches.")
for match in matches:
jenni.msg(trigger.nick,str(match.title.string))
return
team = team.title()
res = False
for match in matches:
if(match.title.string.find(team)!=-1):
jenni.say(str(match.title.string))
res = True
if(res == False):
jenni.reply("Not found ._.")
cricxml.commands = ['cric']
cricxml.priority = 'medium'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment