def trate(): form = TrateForm() global predictors models = (FLAGS.reply_path, FLAGS.thread_path) identifers = (FLAGS.reply_path + "/identifer.bin", FLAGS.thread_path + "/identifer.bin") if validate_on_submit(form): print('post_id:%d' % form.post_id.data) import nowarning import text_predictor as tp if predictors == None: reply_predictor = tp.TextPredictor(identifers[0], models[0]) thread_predictor = tp.TextPredictor(identifers[1], models[1]) predictors = (reply_predictor, thread_predictor) import libtieba as tieba pid = form.post_id.data info = tieba.get_post_info(pid) is_thread = info.IsThread() preidctor = predictors[is_thread] form.score, debug_info = preidctor.predict_debug( info.title, info.content) return render_template('index.html', form=form, info=info, debug_info=debug_info) elif form.title.data != None or form.content.data != None: info = libtieba.PostInfo() if form.title.data == None: info.title = '' elif form.content.data == None: info.content = '' print info.title print info.content return render_template('error.html', form=form)
#!/usr/bin/env python #coding=gbk # ============================================================================== # \file gen-title-content.py # \author chenghuige # \date 2015-12-25 10:04:45.929499 # \Description # ============================================================================== import sys, os import nowarning import libtieba for line in open(sys.argv[1]): pid = line.rstrip().split()[0] pid = int(pid) info = libtieba.get_post_info(pid) print info.title, '\t', info.content.replace('\n', ' ')