#!/usr/bin/python2.2

import urllib, cgi
from Itpl import itpl as i
import cgitb; cgitb.enable()

f = cgi.FieldStorage()
if not f.has_key('s'): 
	print """Content-Type: text/plain

<http://notabug.com/2002/stock?t=symbol> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Property> .
<http://notabug.com/2002/stock?t=symbol> <http://www.w3.org/2000/01/rdf-schema#label> "stock symbol" .
<http://notabug.com/2002/stock?t=price> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Property> .
<http://notabug.com/2002/stock?t=price> <http://www.w3.org/2000/01/rdf-schema#label> "price per share" .
<http://notabug.com/2002/stock?t=lastTradeDay> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Property> .
<http://notabug.com/2002/stock?t=lastTradeDay> <http://www.w3.org/2000/01/rdf-schema#label> "day of the last trade" .
<http://notabug.com/2002/stock?t=lastTradeTime> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Property> .
<http://notabug.com/2002/stock?t=lastTradeTime> <http://www.w3.org/2000/01/rdf-schema#label> "time of the last trade" .
<http://notabug.com/2002/stock?t=change> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Property> .
<http://notabug.com/2002/stock?t=change> <http://www.w3.org/2000/01/rdf-schema#label> "change in price since opening" .
<http://notabug.com/2002/stock?t=Stock> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
<http://notabug.com/2002/stock?t=Stock> <http://www.w3.org/2000/01/rdf-schema#label> "a stock" .
<http://notabug.com/2002/stock?t=open> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Property> .
<http://notabug.com/2002/stock?t=open> <http://www.w3.org/2000/01/rdf-schema#label> "opening price today" .
<http://notabug.com/2002/stock?t=high> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Property> .
<http://notabug.com/2002/stock?t=high> <http://www.w3.org/2000/01/rdf-schema#label> "highest price today" .
<http://notabug.com/2002/stock?t=low> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Property> .
<http://notabug.com/2002/stock?t=low> <http://www.w3.org/2000/01/rdf-schema#label> "lowest price today" .
<http://notabug.com/2002/stock?t=volume> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Property> .
<http://notabug.com/2002/stock?t=volume> <http://www.w3.org/2000/01/rdf-schema#label> "number of shares traded today" .
<http://notabug.com/2002/stock?t=52wkrange> <http://www.w3.org/2000/01/rdf-schema#label> "52-week Range" .
"""
	import sys; sys.exit()
q = f['s'].value
doc = urllib.urlopen('http://finance.yahoo.com/d/quotes.csv?f=sl1d1t1c1ohgvw&e=.csv&s='+q).read()

o = doc.strip().split(',')
start = i('<http://notabug.com/2002/stock?s=$q> <http://notabug.com/2002/stock?t=')
print "Content-Type: text/plain"
print
print i('<http://notabug.com/2002/stock?s=$q> <http://www.w3.org/1999/02/22-rdf-syntax-ns#> <http://notabug.com/2002/stock?t=Stock> .')
print start + i('symbol> $o[0] .')
print start + i('price> "$o[1]" .')
print start + i('lastTradeDay> $o[2] .')
print start + i('lastTradeTime>  $o[3] .')
print start + i('change> "$o[4]" .')
print start + i('open> "$o[5]" .')
print start + i('high> "$o[6]" .')
print start + i('low> "$o[7]" .')
print start + i('volume> "$o[8]" .')
print start + i('52wkrange> $o[9] .')
print i('<http://notabug.com/2002/stock?s=$q> <http://www.w3.org/2000/01/rdf-schema#seeAlso> <http://finance.yahoo.com/q?d=t&s=$q> .')