Skip to content

Instantly share code, notes, and snippets.

@draftcode
Created August 22, 2011 08:40
Show Gist options
  • Select an option

  • Save draftcode/1161944 to your computer and use it in GitHub Desktop.

Select an option

Save draftcode/1161944 to your computer and use it in GitHub Desktop.
import os, re, datetime
class CST_tzinfo(datetime.tzinfo):
def utcoffset(self, dt):
return datetime.timedelta(hours=+8) + self.dst(dt)
def dst(self, dt):
return datetime.timedelta(0)
def tzname(self, dt):
return 'CST'
class JST_tzinfo(datetime.tzinfo):
def utcoffset(self, dt):
return datetime.timedelta(hours=+9) + self.dst(dt)
def dst(self, dt):
return datetime.timedelta(0)
def tzname(self, dt):
return 'JST'
def parse_problems():
rex = re.compile('^<tr align=center><td>(?P<problem>\d+)</td>'
'<td align=left><a lang=".*" href=problem\?id=\d+>(?P<title>.+?)</a>')
for line in open(os.path.expanduser("~/Volume 1.html")).readlines():
matches = rex.match(line)
if matches:
problem = matches.group('problem')
title = matches.group('title')
def parse_status_list():
rex = re.compile('^<tr align=center><td>(?P<runid>\d+)</td>' # runid
'<td><a href=userstatus\?user_id=.*>(?P<userid>.*)</a></td>' # userid
'<td><a href=problem\?id=\d+>(?P<problem>\d+)</a></td>' # problem
'<td>.*<font color=.*>(?P<status>.+)</font>.*</td>' # status
'<td>(?P<memory>.*)</td><td>(?P<runtime>.*)</td>' # memory and runtime
'<td>(?P<language>.+)</td><td>(?P<size>.+)</td>' # language and size
'<td>(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2}) ' # date
'(?P<hour>\d{2}):(?P<minute>\d{2}):(?P<second>\d{2})</td></tr>')
for line in open(os.path.expanduser("~/Problem Status List.html")).readlines():
matches = rex.match(line)
if matches:
rundate = datetime.datetime(
int(matches.group('year')),
int(matches.group('month')),
int(matches.group('day')),
int(matches.group('hour')),
int(matches.group('minute')),
int(matches.group('second')),
0, CST_tzinfo())
runid = int(matches.group('runid'))
userid = matches.group('userid')
problem = matches.group('problem')
status = matches.group('status')
memory = matches.group('memory')
runtime = matches.group('runtime')
language = matches.group('language')
size = int(matches.group('size').strip('B'))
parse_problems()
parse_status_list()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment