인문지식 처리와 프로그래밍2020 5.28-6.4과제 reading
soook
tourSpace01.py
#!/usr/bin/python
#-*- coding: utf-8 -*-
import sys
import pyodbc
import cgi
import cgitb
noIconUrl = "http://dh.aks.ac.kr/VR/style/noicon60.png"
referenceIconUrl = "http://dh.aks.ac.kr/VR/style/text60.png"
networkIconUrl = "http://dh.aks.ac.kr/VR/style/semantic.png"
vrIconUrl = "http://dh.aks.ac.kr/VR/style/vr.png"
def createCZML( poiList ):
for item in poiList:
id = item['id'] # id
label = item['label'] # name
latitude = item['latitude'] # position
longitude = item['longitude'] # position
altitude = item['altitude'] # position
infoUrl = item['infoUrl'] # description
iconUrl = item['iconUrl'] # description
semanticUrl = item['semanticUrl'] # description
vrUrl = item['vrUrl'] # description
descriptionText="<tr height='100px'><td><img width='120' src='{0}'/> <a href='{1}' target='_top'><img width='60' src='{2}'/></a> <a href='{3}' target='_top'><img width='60' src='{4}'/></a> <a href='{5}' target='_top'><img width='60' src='{6}'/></a></td></tr>".format( iconUrl, vrUrl, vrIconUrl, infoUrl, referenceIconUrl, semanticUrl, networkIconUrl )
print descriptionText
def displayData( database, project, condition ):
server = 'tcp:digerati.aks.ac.kr'
username = 'guest'
password = 'guest'
db = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
cur = db.cursor()
geoTable = project +'Space'
comstring = "select id, complex, site, label, latitude, longitude, altitude, infoUrl, iconUrl, vrUrl, semanticUrl from " + geoTable
if condition <> "":
command = comstring + " where {0}".format( condition )
else:
command = comstring
# cur.execute(unicode(command, "utf-8"))
cur.execute( command )
poiList = []
for row in cur.fetchall():
try:
poiList.append( {'id':row[0],'complex':row[1],'site':row[2],'label':row[3],'latitude':row[4],'longitude':row[5],'altitude':row[6],'infoUrl':row[7], 'iconUrl':row[8], 'vrUrl':row[9], 'semanticUrl':row[10] } )
except:
return
cur.close()
db.close()
createCZML( poiList );
def displayResults(template, db, project, condition):
print("Content-type: text/html")
print
f = open(template)
while 1:
line = f.readline()
if not line: break
if( '#YourData' == line.strip()):
displayData( db, project, condition )
else:
print line
f.close()
def main():
reload(sys)
sys.setdefaultencoding('utf8')
cgitb.enable()
form = cgi.FieldStorage()
try:
db = form.getvalue('db', '')
project = form.getvalue('project', '')
key = form.getvalue('key', '')
except:
return
if key <> '' :
condition = "complex='" + key + "'"
else:
condition=''
displayResults("templateTbl.htm", db, project, condition )
main()
templateTbl.htm
- tour불러서 table 형태로 보여주는 html파일
<!--Template for displying search results, Center for DH at AKS-->
<html>
<head>
<title>Retrieved Data Set</title>
<meta charset="UTF-8"/>
<style>
table {
border:1px solid #444444;
text-align:left;
width:100%;
color:#202020;
font-size:15px;
font-family:함초롬바탕;
}
table th {
background-color:Olive;
color:White;
}
table tr:nth-child(odd) td{
background:#ffffff;
}
table tr:nth-child(even) td{
background:#dfdfdf;
}
td {
padding: 5px 10px 5px 10px;
}
</style>
</head>
<body>
<table>
#YourData
</table>
</body>
</html>