易經查詢系統-程式碼 (1)

功能 1:

# -*- coding: utf-8 -*- import os import cgi from urllib2 import * hostSolr = 'localhost:8080' try: hostSolr = os.environ['HTTP_HOST'] except: pass form = cgi.FieldStorage() id = form.getfirst('id', '01') serviceURL = "http://%s/solr/taichi64/select?q=id:%s" % (hostSolr, id) print "Content-type: text/html; charset=utf-8\n\n\n\n" print "<html><head>\n" print "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />" print "<title>易經-%s</title>\n" % (id) print "</head><body>\n" print "<table border='1' width='800'>" print "<tr align='center'>" print "<td><img src='../images/%s-0.png'></td>" % (id) print "<td bgcolor='silver' colspan='2' width='90%'>說明</td></tr>" try: solrInst = urlopen("%s&wt=python" % serviceURL) resultList = eval( solrInst.read() ) for hit in resultList['response']['docs']: print "<tr><td bgcolor='silver' align='center'>卦名</td>" print "<td colspan='2'>%s</td></tr>" % (hit['name'].encode('utf-8')) sku = hit['sku'].split('|') print "<tr><td bgcolor='silver' align='center'>座標</td><td>%s</td><td>%s</td></tr>" %

(sku[1].encode('utf-8'), sku[0].encode('utf-8')) for title in hit['title']: print "<tr><td bgcolor='silver' align='center'>簡說</td><td colspan='2'>%s</td></tr>" % (title.encode('utf-8')) print "<tr><td bgcolor='silver' align='center'>詳述</td><td colspan='2'><ul>" desc = hit['description'].split('|') for ds in desc: print "<li>%s</li>" % (ds.encode('utf-8')) print "</ul></td></tr>" print "<tr><td bgcolor='silver' align='center'>問事</td><td colspan='2'><table border='1' width='100%'>" for feature in hit['features']: direction = feature.split('|') print "<tr><td bgcolor='silver' align='center'>%s</td><td>%s</td></tr>" %

(direction[0].encode('utf-8'), direction[1].encode('utf-8')) print "</table></td></tr>" print "<tr><td bgcolor='silver' align='center'>建議</td><td colspan='2'><ul>" comments = hit['comments'].split('|') for cmnt in comments: print "<li>%s</li>" % (cmnt.encode('utf-8')) print "</ul></td></tr>" except: print "<tr><td bgcolor='silver' align='center'>除錯:</td><td colspan='2'><a href='%s' target='_blank'>原始資料</a></td></tr>" % (serviceURL) print "</table>" print "</body>" print "</html>"