-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathechess_parser.py
More file actions
40 lines (34 loc) · 1.09 KB
/
echess_parser.py
File metadata and controls
40 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import sys
import fetch
import feedparser
import re
def parseRSS(URL):
p = fetch.HTMLpage(URL)
p.fetch_page()
atom = feedparser.parse(p.raw())
p = re.compile('Rating: \d+<br />Time Left: ((?:\d+ days? \d+ hours?)|(?:1 day)|(?:\d+ hours? \d+ minutes?))( )?<br />Move #: \d+')
times = []
for entry in atom.entries:
m = p.match(entry.description)
if m:
times.append(m.group(1))
if len(atom.entries) > 0:
# times.sort()
# p = re.compile('(\d{2}):(\d{2})')
# m = p.match(times[0])
# time = m.group(1) + ":" + m.group(2)
if len(atom.entries) > 1:
print "%s games ready." % len(atom.entries)
else:
print "One game ready."
print "(%s remaining)." % times[0]
else:
print "No games ready."
if __name__ == "__main__":
if len(sys.argv) < 2:
print "Usage: python " + sys.argv[0] + " username"
exit()
uname = sys.argv[1]
_URL = "http://www.conquerclub.com/rss.php?username=" + uname
URL = "http://www.chess.com/rss/echess/" + uname
parseRSS(URL)