there's no python section so i guess i'll put this here. this is just for educational purposes.
the function 'expand' takes a list of trackback urls with the form: http:// someblog.com/blah/
1234 and a number.
for example the number 2 would yield 4 more urls per url. with the url http:// someblog.com/blah/1234 and the number 2 you would get:
http:// someblog.com/blah/1232
http:// someblog.com/blah/1233
http:// someblog.com/blah/1235
http:// someblog.com/blah/1236
import re
def up(num, dif):
vals = []
for i in xrange(dif):
num += 1
vals.append(num)
return vals
def down(num, dif):
vals = []
if num > 1:
count = 0
while num > 1 and count < dif:
num -= 1
vals.append(num)
count += 1
return vals
else:
return [num]
def expand(trackbacks, dif):
new_urls = []
for trackback in trackbacks:
m = re.match('(http[^"\s]+/)([0-9]+)[/]?$', trackback)
if m:
url = m.group(1)
post_id = int(m.group(2))
ids = []
ids.extend(up(post_id, dif))
ids.extend(down(post_id, dif))
new_urls.extend([url + str(id) for id in ids])
return new_urls