#!/bin/python3 import os #add script's directory to PATH __location__ = os.path.realpath( os.path.join(os.getcwd(), os.path.dirname(__file__))) links = open(os.path.join(__location__, "links.txt"), "r") header = open(os.path.join(__location__, "header.html"), "r") footer = open(os.path.join(__location__, "footer.html"), "r") out = open(os.path.join(__location__, "links.html"), "w") out.write(header.read()) line = links.readline() # state NONE = 0 TITLE = 1 NAME = 2 URL = 3 state_graph = { '#': TITLE, '[': NAME, ']': NONE, '(': URL, ')': NONE } closing_pairs = { '{':'}', '[':']', '(':')' } state = NONE url_name = "" while(line): if line[0] == '~': line = links.readline() continue if line[0] == '#': out.write("") for c in closing_pairs: i = line.find(c) if i > -1: j = line.find(closing_pairs[c]) if(c == -1): quit() content = line[i+1:j] if c == '{': out.write( "