#!/usr/bin/env python # -*- coding: utf-8 -*- """ blacklist_builder.py Get the entries from a blacklist and print them to standard output """ import urllib2, re latest = urllib2.urlopen("http://www.unknowngenius.com/blog/blacklist/") prefix = 'RewriteEngine on' suffix = 'RewriteRule /(.*) / [F,L]' str = [prefix] begin = "RewriteCond %{HTTP_REFERER} ^.*" for line in latest: print '.', str.append(begin + re.sub('(\s#:url:|\s#:regex-url:|\s#:rbl:)', ".*$ [OR,NC]", line)) str.append(suffix) file('.htaccess', 'w').write('\n'.join(str))
Use of list to speed up.
Added prefix and suffix to make it a complete rewrite.