'''
write_file(base)
def generate_end_file() :
base = '''
'''
write_file(base)
def generate_image(path) :
base = '''
'''
write_file(base)
def set_foldername(name) :
os.mkdir("../images/"+name)
onlyfiles = [f for f in listdir(".") if isfile(join(".", f))]
for f in onlyfiles :
if f.endswith(".jpg") or f.endswith(".jpeg") or f.endswith(".png") or f.endswith(".ico") or f.endswith(".gif") :
shutil.move(f, "../images/"+name+"/"+f)
def main() :
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filename = askopenfilename() # show an "Open" dialog box and return the path to the selected file
name = ""
titre = ""
date = ""
was_list = False
with open(filename, "r") as a :
for line in a.readlines() :
if line.startswith("~foldername~") :
final_line = line.replace("~foldername~","").strip()
name = final_line
set_foldername(final_line)
elif line.startswith("~titre~") :
final_line = line.replace("~titre~","").strip()
titre = final_line
generate_base(final_line)
elif line.startswith("~date~") :
final_line = line.replace("~date~","").strip()
date = " " + final_line
generate_date(final_line)
elif line.startswith("~section~") :
final_line = line.replace("~section~","").strip()
generate_section(final_line)
elif line.startswith("~image~") :
final_line = line.replace("~image~","").strip()
final_line = "../images/"+name+"/" + final_line
generate_image(final_line)
else :
if line.startswith("~endlist~"):
was_list = False
write_file("")
continue
if line.startswith("~list~") :
l = line.split("~list~")
res = ""
if not was_list :
res += "
"
for w in l :
if not w == " " and not w == "" and not w == "\n":
res += "
"+w+"
"
was_list = True
line = res
if "~data~" in line :
l = line.split("~data~")
res = ""
for w in l :
if not w.startswith(" ") and not w.endswith(" ") and not "
'+w+''
else :
res += w
line = res
if "~link~" in line :
l = line.split("~link~")
res = ""
for w in l :
if not w.startswith(" ") and not w.endswith(" ") and not w == "":
link = w.split("]")
if len(link) < 2 :
continue
res += ''+link[1]+''
else :
res += w
line = res
if not was_list :
write_file("
" + line.strip() + "
")
else :
write_file(line.strip())
generate_end_file()
shutil.move("out.html", "../pages/"+name+".html")
base = '''\n\t\t
\n'''
with open("../pages/blog.html", "r+") as f :
lines = f.readlines()
for i, line in enumerate(lines):
if "" in line :
lines[i+1] = lines[i+1].strip() + base
f.seek(0)
for line in lines:
f.write(line)
if __name__ == "__main__" :
main()