#!/usr/bin/python2.4 # -*- coding: utf-8 -*- import sys, os, cgi, codecs #import cgitb; cgitb.enable() from BeautifulSoup import UnicodeDammit import vecid print "Content-Type: text/html\n\n" sys.stdout = codecs.getwriter('utf-8')(sys.stdout) form = cgi.FieldStorage() mystery = form['mystery'].value mystery = UnicodeDammit(mystery).unicode def heading(s): return "

" + s + "

" answers = vecid.id(mystery, threshhold=1) answers.reverse() if max([score for score, lang in answers]) < 0.4: answer = heading("Sorry, language unknown.") else: answer = heading(answers[0][1]) #answer = '

' + answers[0][1] + '

' #pat = "

%.3f %s

" #answers = '\n'.join([pat % (score, lang) for score,lang in answers]) print unicode(answer) """ header = UnicodeDammit(open('header', 'U').read()).unicode tween = UnicodeDammit(open('tween', 'U').read()).unicode results = unicode(answers) tailer = UnicodeDammit(open('tailer', 'U').read()).unicode print header + mystery + tween + results + tailer """