"인문지식 처리와 프로그래밍2020 5.28-6.4과제 reading"의 두 판 사이의 차이

soook
이동: 둘러보기, 검색
114번째 줄: 114번째 줄:
 
</pre>
 
</pre>
  
[http://dh.aks.ac.kr/~sandbox/public_html/cgi-bin/tour/templateTbl.htm]
+
[http://dh.aks.ac.kr/~sandbox/cgi-bin/tour/templateTbl.htm templateTbl.htm]
[http://dh.aks.ac.kr/~sandbox/cgi-bin/tour/tourSpace01.py?db=common&project=tour&key=tour2011-3 ]
+
[http://dh.aks.ac.kr/~sandbox/cgi-bin/tour/tourSpace01.py?db=common&project=tour&key=tour2011-3 tour2011-3]

2020년 6월 3일 (수) 22:58 판



#!/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 tour2011-3