kmj
06-26-2002, 06:25 PM
Maybe I'll turn this into a moobot module, if Strike will let me. And yeah, I know I probably should have used regular expression objects instead of re.sub directly, but since I'm not using anything twice, I fail to see any efficiency improvements.
import httplib
import re
import sys
conn = httplib.HTTPConnection('www.coderforums.net')
conn.request('GET', "")
response = conn.getresponse()
if response.status != 200:
print "bad response from coderforums:", response.status
sys.exit()
data = response.read()
data = re.sub('<.*?>', '', data)
match = re.search('on the boards.*?Number of Active', data, re.DOTALL)
if match is None:
print "data not found; gosh that sucks"
sys.exit()
data = data[match.start():match.end()]
data = re.sub('\s', '', data)
data = re.sub('(ontheboards\.)|(NumberofActive)', '', data)
data = re.sub(',',', ', data)
print data
Of course this will fail if Nafae changes that specific area of the frontpage.
import httplib
import re
import sys
conn = httplib.HTTPConnection('www.coderforums.net')
conn.request('GET', "")
response = conn.getresponse()
if response.status != 200:
print "bad response from coderforums:", response.status
sys.exit()
data = response.read()
data = re.sub('<.*?>', '', data)
match = re.search('on the boards.*?Number of Active', data, re.DOTALL)
if match is None:
print "data not found; gosh that sucks"
sys.exit()
data = data[match.start():match.end()]
data = re.sub('\s', '', data)
data = re.sub('(ontheboards\.)|(NumberofActive)', '', data)
data = re.sub(',',', ', data)
print data
Of course this will fail if Nafae changes that specific area of the frontpage.