作者: 機械伯爵
日時: 2002/10/29(00:16)
 誰でも書けるHTML自動作成スクリプト(全くひねり無し)

 誰でも書けるけど、書こうと思うと結構面倒なので、載せときます。

 HTML4.0とXHTML1.0、及び各種日本語コードに対応。

 raw文字列も日本語ガイドも無いので、Python1.0.1でも、英語版コンソール
でも動きます。

--^ mkhtml.py
# Make HTML (or XHTML) File Template
c = ["EUC-JP","UTF-8","ISO-2022-JP","Shift_JIS"]
xx = ["HTML 4.0","XHTML 1.0"]
while 1:
    print "Input file name"
    filename = raw_input(">>> ")
    print "Input title"
    title = raw_input(">>> ")
    print "What's a format ?"
    print "(0)HTML 4.0 or (1)XHTML 1.0 ?"
    xhtml = input(">>> ")
    print "What's a character set?"
    print "(0)EUC or (1)UTF-8 or (2)JIS or (3)Shift JIS ?"
    charcode = input(">>> ")
    print "FILE   :",filename + ".html"
    print "TITLE  :",title
    print "FORMAT :",xx[xhtml]
    print "CHARACTER SET : ",c[charcode]
    go = input("(0)Retry or (1)OK ? >> ")
    if go : break

style = filename + ".css"
filename = filename + ".html"
title = "<title>" + title + "</title>\n"

f = open(filename, "w")
if xhtml :
    f.write("<?xml ver=\"1.0\" encoding=\"" + c[charcode] + "\"?>\n")
    f.write("<!DOCTYPE html PUBLIC \"-//W3C/DTD XHTML 1.0 Strict//EN\"\n")
    f.write("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n")
    f.write("<html xmlns=\"http://www.w3.org/1999/xml\">\n")
else:
    f.write("<!DOCTYPE HTML PUBLIC \"-//W3C/DTD HTML 4.0//EN\">\n")
    f.write("<html lang=\"ja\">\n")
f.write("<head>\n")
f.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" +
c[charcode] +"\" />\n")
f.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + style + "\"
/>\n")
f.write(title)
f.write("</head>\n<body>\n")
f.write("</body>\n</html>\n")
f.close()

print "DONE!"
--$