Lately I’ve been playing around with Linode. One of the neat (but incomplete, hard to use, and not as good as it could be) features are Linode Stack Scripts. I wanted a full set of them to work with in constructing my own. Browsing through them graphically is a hassle, making it hard to
Season to taste, public domain license!
import re import urllib import htmlentitydefs exp = re.compile( '''\[CDATA\[\n\n''' + \ '(.*?)' + \ '\n\]\]>\\</div>', re.DOTALL | re.VERBOSE) myrx = re.compile('&(' + '|'.join(htmlentitydefs.entitydefs.keys()) + ');') def dehtml(s): return re.sub( myrx, lambda m: htmlentitydefs.entitydefs[m.group(1)], s ) last_seen = 0 ii = 0 while 1: ii += 1 if ii - last_seen > 100: print ("stopping at %i" % ii) break # we've probably seen them all try: text = urllib.urlopen("http://www.linode.com/stackscripts/view/?StackScriptID=%i#viewSource" % ii).read() except: continue try: ans = exp.search(text).groups()[1:] except: continue ans = dehtml(ans) last_seen = ii print ("creating stackscript_%i.sh" % ii) ofh = file("stackscript_%i.sh" % ii,'w') ofh.write(ans) ofh.close()