Implement a skybot plugin to announce upcoming Dota 2 matches.
There is a pre-parsed match list available at
- Download the match list from the API
- The API returns a json formatted array that contains html markup, one item for every upcoming match.
- Python parses json easily.
- Parse the list using regex
- The HTML markup needs to be parsed with regex to obtain match info that can be processed by python.
- see below for samples and the regex pattern to use
- Repeat on a fixed timer or sleep
- Set up a timer or sleep scheduled for the next match time
- Make an announcement when the sleep or timer is up
- Respond to user queries with upcoming match info
The API returns match info in html like so
<tr class='d2mtrow eventSoon' href='http://www.joindota.com/en/matches/109633' title='joinDOTA League Asia Season 1 - Lower-Bracket Final' rel='tooltip' id='109633'><td alt='1397138400' class='push-tt jd_date'>23m</td><td><img src='http://flags.cdn.gamesports.net/ph.gif' title='Philippines' width='14px' height='9px'> Exe.TnC</td><td>v</td><td><img title='Indonesia' src='http://flags.cdn.gamesports.net/id.gif' width='14px' height='9px'> RRQ</td></tr>
Use this regex to parse it
<tr class='d2mtrow eventSoon' href='(?P<jdurl>.*?)' title='(?P<title>.*?)' rel='tooltip' id='\d*'><td alt='(?P<timestamp>\d*)' class='push-tt jd_date'>.*?</td><td><img .*?>\s?(?P<team1>.*?)</td><td>v</td><td><img .*?>\s?(?P<team2>.*?)</td></tr>
The regex returns named groups:
- jdurl - the URL e.g. http://www.joindota.com/en/matches/109633
- title - the Match Title eg. joinDOTA League Asia Season 1 - Lower-Bracket Final
- timestamp - the Match scheduled time as a unix timestamp e.g. 1397138400
- team1 and team2 - Team names e.g. Exe.TnC and RRQ
Use this code to parse it
# jdregex contains the regex
jdregex = r"(?i)<tr class='d2mtrow eventSoon' href='(?P<jdurl>.*?)' title='(?P<title>.*?)' rel='tooltip' id='\d*'><td alt='(?P<timestamp>\d*)' class='push-tt jd_date'>.*?</td><td><img .*?>\s?(?P<team1>.*?)</td><td>v</td><td><img .*?>\s?(?P<team2>.*?)</td></tr>"
# markup contains the HTML markup for one match
matchinfo = re.findall(jdregex, markup)
# now matchinfo contains the parsed data
# e.g. matchinfo['title'] gives you the parsed title