# $Id$ # push contents from multipage text file import sys, re import infogamibot import urlparse ET = infogamibot.ET try: site = sys.argv[1] if "@" not in site: raise IndexError filename = sys.argv[2] except IndexError: print "usage: infogami-push user:pass@site filename" sys.exit(1) bot = infogamibot.Bot(site) pages = set() def upload(body): if not body: return page = body.pop(0)[3:].strip() while body and not body[0].strip(): body.pop(0) if page in pages: raise ValueError("duplicate page name: %r" % page) pages.add(page) if body and body[0].startswith("#"): title = body.pop(0).lstrip("#").strip() else: title = page body = "".join(body) print page, "..." bot.update(page, title, body) body = [] for line in open(filename): if line.startswith("==="): upload(body) body = [line] else: body.append(line) upload(body)