#!/bin/usr/env python # -*- coding: utf-8 -*- from xml.etree import ElementTree from urllib import urlopen from tempfile import NamedTemporaryFile from subprocess import call import wiki2texi p=urlopen("http://wiki.archlinux.org/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles=Beginners%20Guide") tree = ElementTree.parse(p) title= tree.getroot().find(".//page").attrib["title"] data = tree.getroot().findtext(".//rev").splitlines(1) #strip Obtain Media upto Documentation i= 0 strip = False while i < len(data): line = data[i] if strip: #strip upto if "Start the Installation" in line: break del(data[i]) else: #strip from if "Obtain the latest Installation media" in data[i]: strip = True else: i += 1 texi= NamedTemporaryFile() texi.write((wiki2texi.main(data,title+".texi",title).encode("utf8"))) texi.seek(0) output = NamedTemporaryFile("rw") if call(["makeinfo", "--plaintext", "--fill-column=80", "-o"+output.name, texi.name]) != 0: print("makeinfo failed") exit(1) output.seek(0) print(output.read()) # vim: set ai ts=4 sw=4 et: