def main(): loginspider().update_md() mdfiles = os.listdir('./md') for file in mdfiles: html_name = '%s/%s.html' % ('./html', file[:-3]) if not os.path.isdir(file) and not os.path.exists(html_name): md2html.md2html(file, html_name)
def myapp(environ, start_response): """ myapp """ # 确保正确处理中文 filepath = environ['SCRIPT_FILENAME'].decode('utf-8') if not os.path.exists(filepath): start_response('404 Not Found', [('Content-Type', 'text/plain')]) return ['404 Not Found!\n'] if filepath[-3:] == '.md': start_response('200 OK', [('Content-Type', 'text/html')]) infile = open(filepath, 'r') md_str = infile.read() infile.close() input_str = unicode(md_str, 'utf-8') output_str = md2html(input_str) return [output_str.encode('utf-8')] else: start_response('200 OK', [('Content-Type', 'text/plain')]) infile = open(filepath, 'r') file_str = infile.read() infile.close() return [file_str]
def main(dir): testdoc.wordsToHtml(dir) filelist = testdoc.wordsTotxt(dir) print filelist filelist1 = [] for files in filelist: filelist1.append(os.path.splitext(files)[0]) print filelist1 for files in filelist1: temppath = files + '.files' havepicornot = os.path.exists(temppath) if havepicornot: print temppath renamepic.renamepic(temppath) renamepic.outputtxt(temppath) for files in filelist1: outputtxt.output(files, havepicornot) md2html.md2html(dir)
def GET(self, postId): post = web.ctx.orm.query(Post).filter_by(id=postId).first() if post: f = os.path.join('articles', post.filename) else: raise web.NotFound # mdFile = codecs.open(f, mode='r', encoding='utf8') mdFile = open(f, encoding='utf-8') content = mdFile.read() html = md2html(content) mdFile.close() # html = md2html('articles/' + post.filename) return render_template('view.html', html=html, post=post)
def blog(): file = open(txt_src_folder + "blog.md", "r") html = html_head("bl0g") + "<body>" + top_bar('blog') + md_file2html(file) html = html + md2html(blog_dynamic(blog_src_folder)) # dynamic content return html + "</body></html>"
def main(): loginspider().update_md() mdfiles = os.listdir('./md') for file in mdfiles: html_name = '%s/%s.html' % ('./html', file[:-3]) if not os.path.isdir(file) and not os.path.exists(html_name): md2html.md2html(file, html_name) def parse_arg(): parser = argparse.ArgumentParser() parser.add_argument("-u", "-username", help='username', type = str, dest='username', required=True) parser.add_argument("-p", "-passwd", help='password', type = str, dest='passwd', required=True) parser.add_argument("-update", type=str, help='update', dest="update", choices=['md', 'html']) return parser.parse_args() if __name__ == '__main__': args = parse_arg() print(args) spider = loginspider(args.username, args.passwd) spider.update_md() if args.update == 'html': for file in mdfiles: html_name = '%s/%s.html' % ('./html', file[:-3]) if not os.path.isdir(file) and not os.path.exists(html_name): md2html.md2html(file, html_name)