Py2Html

Python-Command Line Python-To-Html Converter. Makes posting Python to blogs quick.

by: Daniel Folkes

This is Licensed under GPLv3. Give Back.

Py2Html

    Download Source

  1. print “”” This is a simple program that takes a python file and replaces the
  2. plain text punctuation with the easily postable html code.
  3. written by :    Daniel Folkes
  4.         danfolkes @t [email protected] d0t c0m
  5.         http://danfolkes.com
  6. “””
  7. import sys
  8. input = “NonValidInput”
  9. if sys.argv[1]:
  10.     input = sys.argv[1]
  11. else:
  12.     input = raw_input(“What is your input file?:”)
  13. ifile = file(input)
  14. output = input + “.html”
  15. if sys.argv[2]:
  16.     output = sys.argv[2]
  17. ofile = file(output, ‘w’)
  18. outstring = “”
  19. #———–consts————-
  20. tab = ”    ”
  21. space = ” ”
  22. el = “<br />”
  23. start = “<li>”
  24. end = “</li>”
  25. Pstart = “<ol>”
  26. Pend = “</ol>”
  27. convertTup = ((“<“,”<“),(“>”,”>”))
  28. #——-consts[end]————
  29. outstring += Pstart
  30. while 1:
  31.     line = ifile.readline()
  32.     if len(line) == 0:
  33.         break
  34. #    line = line.replace(“<“,”<“)
  35. #    line = line.replace(“>”,”>”)
  36. #    line = line.replace(“&”,”&”)
  37.     for tup in convertTup:
  38.         line = line.replace(tup[0],tup[1])
  39.     line = line.replace(“\t”,tab)
  40.     line = start + line + end
  41.     outstring += line
  42. outstring += Pend
  43. ofile.write(outstring)
  44. ofile.close()
  45. ifile.close()
Facebooktwittergoogle_pluspinterest