Python-Command Line Python-To-Html Converter. Makes posting Python to blogs quick.
by: Daniel Folkes
This is Licensed under GPLv3. Give Back.
- Download Source
- print “”” This is a simple program that takes a python file and replaces the
- plain text punctuation with the easily postable html code.
- written by : Daniel Folkes
- danfolkes @t gm@il d0t c0m
- http://danfolkes.com
- “””
- import sys
- input = “NonValidInput”
- if sys.argv[1]:
- input = sys.argv[1]
- else:
- input = raw_input(“What is your input file?:”)
- ifile = file(input)
- output = input + “.html”
- if sys.argv[2]:
- output = sys.argv[2]
- ofile = file(output, ‘w’)
- outstring = “”
- #———–consts————-
- tab = ” ”
- space = ” ”
- el = “<br />”
- start = “<li>”
- end = “</li>”
- Pstart = “<ol>”
- Pend = “</ol>”
- convertTup = ((“<“,”<“),(“>”,”>”))
- #——-consts[end]————
- outstring += Pstart
- while 1:
- line = ifile.readline()
- if len(line) == 0:
- break
- # line = line.replace(“<“,”<“)
- # line = line.replace(“>”,”>”)
- # line = line.replace(“&”,”&”)
- for tup in convertTup:
- line = line.replace(tup[0],tup[1])
- line = line.replace(“\t”,tab)
- line = start + line + end
- outstring += line
- outstring += Pend
- ofile.write(outstring)
- ofile.close()
- ifile.close()