PDA

View Full Version : Script to view active members of coderforums.net


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.

Strike
06-26-2002, 08:20 PM
Let you? You don't need my permission to make it a moobot module. You just need one of us (me or Bradmont) to add it into the official source if you want it to be distributed with moobot.

jemfinch
06-26-2002, 08:40 PM
Python's re module caches recently used regular expressions. I think it caches up to 20; if your program uses any less than that it won't be significantly slower than if you use the regexp objects themselves.

Jeremy

kmj
06-26-2002, 08:43 PM
Originally posted by Strike
Let you? You don't need my permission to make it a moobot module. You just need one of us (me or Bradmont) to add it into the official source if you want it to be distributed with moobot.

actually, I have access to the source tree anyway, since I'm on the developer list, no? I'd have to set up cvs at home though. Or maybe I'll do it tomorrow at work.

inkedmn
06-27-2002, 11:35 PM
that's pretty slick man :)

kmj
06-28-2002, 11:45 AM
thanks :D It's not much, as you can see.