[cvs-annodex] commit (/annodex): cmmlwiki/trunk/cmmlwiki-admin
cmmlwiki/trunk/cmmlwiki-import cmmlwiki/trunk/edit.cgi
cmmlwiki/trunk/view.cgi
conrad
nobody at lists.annodex.net
Tue Apr 12 12:43:17 EST 2005
Update of /annodex (new revision 1240)
Modified files:
cmmlwiki/trunk/cmmlwiki-admin
cmmlwiki/trunk/cmmlwiki-import
cmmlwiki/trunk/edit.cgi
cmmlwiki/trunk/view.cgi
Log Message:
parse and generate npt timestamps, and check validity of all attributes before
attempting to generate HTML and CMML
Modified: cmmlwiki/trunk/cmmlwiki-admin
===================================================================
--- cmmlwiki/trunk/cmmlwiki-admin 2005-04-12 01:26:38 UTC (rev 1239)
+++ cmmlwiki/trunk/cmmlwiki-admin 2005-04-12 02:43:16 UTC (rev 1240)
@@ -65,7 +65,7 @@
sql = """CREATE TABLE clips (
ixc INTEGER PRIMARY KEY,
ixp INTEGER,
- start_time INTEGER,
+ start_time FLOAT,
id VARCHAR(20),
a_href VARCHAR(80),
img_src VARCHAR(80),
Modified: cmmlwiki/trunk/cmmlwiki-import
===================================================================
--- cmmlwiki/trunk/cmmlwiki-import 2005-04-12 01:26:38 UTC (rev 1239)
+++ cmmlwiki/trunk/cmmlwiki-import 2005-04-12 02:43:16 UTC (rev 1240)
@@ -11,6 +11,7 @@
# Conrad Parker <conrad at annodex.net>, Mar 3 2005
import sys
+import re
from time import strptime, strftime
import sqlite
@@ -25,6 +26,20 @@
t = strptime(str, "clock:%Y%m%dT%H%M%SZ")
return strftime ("%H:%M:%S", t)
+def npt2timestamp(str):
+ match = re.search ('^npt:(\d*):(\d\d):(\d\d).(\d\d\d)', str)
+ if match:
+ hh = int(match.group(1))
+ mm = int(match.group(2))
+ ss = int(match.group(3))
+ ms = int(match.group(4))
+ total = float((((hh * 60) + mm) * 60) + ss)
+ total += ms/1000.0
+ else:
+ total = -1.0
+
+ return total
+
class cmmlHandler(saxutils.DefaultHandler):
def __init__(self, cur, ixp):
self.inDesc = False
@@ -41,7 +56,8 @@
self.vals['img_src'] = ""
self.vals['a_href'] = ""
self.vals['id'] = attrs.get('id')
- self.vals['start'] = attrs.get('start')
+ #self.vals['start'] = attrs.get('start')
+ self.vals['start'] = npt2timestamp(attrs.get('start'))
self.vals['end'] = attrs.get('end')
#self.start_time = clock2timestamp(attrs.get('start', None))
@@ -65,7 +81,7 @@
def endElement(self, name):
if name == 'clip':
sql = """INSERT INTO clips (ixp, start_time, id, img_src, a_href, desc)
- VALUES (%(ixp)s,%(start)s,%(id)s,%(img_src)s,%(a_href)s,%(desc)s) """
+ VALUES (%(ixp)s,%(start)f,%(id)s,%(img_src)s,%(a_href)s,%(desc)s) """
#print sql
cur.execute(sql, self.vals)
# print """<div id="%(id)s" class="clip">
Modified: cmmlwiki/trunk/edit.cgi
===================================================================
--- cmmlwiki/trunk/edit.cgi 2005-04-12 01:26:38 UTC (rev 1239)
+++ cmmlwiki/trunk/edit.cgi 2005-04-12 02:43:16 UTC (rev 1240)
@@ -163,10 +163,19 @@
else:
return ''
-def key_isprintable (dict, key):
- return (dict.has_key(key) and dict[key] != None and dict[key] != '')
+def time2npt (t):
+ it = int(t)
+ ms = (t*1000) - (float(it) * 1000)
+ ss = it % 60
+ mm = ((it-ss)/60) % 60
+ hh = ((it-(mm*60)-ss)/3600) % 60
+ return "npt:%d:%02d:%02d.%03d" % (hh, mm, ss, ms)
+
def toc(ixp):
+ def key_isprintable (dict, key):
+ return (dict.has_key(key) and dict[key] != None and dict[key] != '')
+
content_type ("text/html")
con = sqlite.connect(db)
@@ -212,7 +221,7 @@
print '<h3>'
if (key_isprintable (row, 'clips.start_time')):
- print '%s' % row['clips.start_time']
+ print '%s' % time2npt (row['clips.start_time'])
if (key_isprintable (row, 'clips.id')):
print ': %(clips.id)s' % row
print '</h3>'
@@ -242,7 +251,7 @@
if (key_isprintable (row, 'clips.id')):
print '[<a href="%s/%s?id=%s">view</a>]' % (view_base, name, row['clips.id'])
elif (key_isprintable (row, 'clips.start_time')):
- print '[<a href="%s/%s?t=%s">view</a>]' % (view_base, name, row['clips.start_time'])
+ print '[<a href="%s/%s?t=%s">view</a>]' % (view_base, name, time2npt(row['clips.start_time']))
if (key_isprintable (row, 'clips.ixc')):
Modified: cmmlwiki/trunk/view.cgi
===================================================================
--- cmmlwiki/trunk/view.cgi 2005-04-12 01:26:38 UTC (rev 1239)
+++ cmmlwiki/trunk/view.cgi 2005-04-12 02:43:16 UTC (rev 1240)
@@ -1,5 +1,6 @@
#!/usr/bin/python
+import re
import sys
import os
import cgi
@@ -15,29 +16,28 @@
print "Content-Type: %s\n" % ct
sys.stdout.flush()
-# Define function to generate HTML form.
-def generate_form():
- content_type ("text/html")
+def npt2timestamp(str):
+ match = re.search ('^npt:(\d*):(\d\d):(\d\d).(\d\d\d)', str)
+ if match:
+ hh = int(match.group(1))
+ mm = int(match.group(2))
+ ss = int(match.group(3))
+ ms = int(match.group(4))
+ total = float((((hh * 60) + mm) * 60) + ss)
+ total += ms/1000.0
+ else:
+ total = 0.0
- print """
-<html>
-<head>
-<title>Info form</title>
-</head>
-<body bgcolor="white">
-<h3>Please, enter your name and the URL of your favourite site.</h3>
-<form method="get" action="dynamo.py">
-<table border="0">
-<tr><th>Name:</th><td><input type="text" name="name"></td></tr>
-<tr><th>URL:</th><td><input type="text" name="url"></td></tr>
-</table>
-<input type="hidden" name="action" value="display"/>
-<input type="submit" value="Enter"/>
-</form>
-</body>
-</html>
-"""
+ return total
+def time2npt (t):
+ it = int(t)
+ ms = (t*1000) - (float(it) * 1000)
+ ss = it % 60
+ mm = ((it-ss)/60) % 60
+ hh = ((it-(mm*60)-ss)/3600) % 60
+ return "npt:%d:%02d:%02d.%03d" % (hh, mm, ss, ms)
+
def anxenc(ixp, id="", t=0.0):
content_type ("application/x-annodex")
@@ -52,25 +52,32 @@
# Work out the named time offset
if (id == ""):
- offset = float(t)
+ try:
+ offset = float(t)
+ except ValueError:
+ offset = npt2timestamp(t)
else:
- sql = "SELECT * FROM clips WHERE id='%s'" % id
+ sql = 'SELECT * FROM clips WHERE ixp="%s" AND id="%s"' % (ixp, id)
cur.execute(sql)
row = cur.next()
offset = (row['start_time'])
+ #content_type ('text/plain')
+ #print 'cmmlwiki::anxenc: source %s, offset %f, id %s' % (source, offset, id)
+ #sys.exit(0)
+
# Begin the import
annodex.init_importers("*/*")
anx = annodex.Anx(1, "w")
anx.writer_import(source, offset=offset)
# Insert clips
- sql = 'SELECT * FROM clips WHERE ixp="%s" ORDER BY start_time' % ixp
- cur.execute(sql)
- for row in cur.fetchall():
- clip = annodex.Clip(anchor=annodex.Anchor(text="%(a_href)s" % row,
- href="%(a_href)s" % row))
- anx.insert(clip, row['start_time']);
+ #sql = 'SELECT * FROM clips WHERE ixp="%s" ORDER BY start_time' % ixp
+ #cur.execute(sql)
+ #for row in cur.fetchall():
+ # clip = annodex.Clip(anchor=annodex.Anchor(text="%(a_href)s" % row,
+ # href="%(a_href)s" % row))
+ # anx.insert(clip, row['start_time']);
# Generate Annodex media
while 1:
@@ -78,7 +85,15 @@
if (x == 0):
break
-def fake_cmml(ixp):
+
+def make_cmml(ixp):
+ def key_isprintable (dict, key):
+ return (dict.has_key(key) and dict[key] != None and dict[key] != '')
+
+ def escape(str):
+ s = re.sub ("<", "<", str)
+ return (re.sub (">", ">", s))
+
content_type ("text/x-cmml")
print preamble
@@ -91,15 +106,28 @@
con = sqlite.connect(db)
cur = con.cursor()
+ #sql = 'SELECT * FROM clips'
sql = 'SELECT * FROM clips WHERE ixp="%s" ORDER BY start_time' % ixp
cur.execute(sql)
for row in cur.fetchall():
- print """<clip start="%(start_time)s">
-<a href="%(a_href)s">%(a_href)s</a>
-<img src="%(img_src)s"/>
-<desc>%(desc)s</desc>
-</clip>""" % row
+ print '<clip'
+ if (key_isprintable (row, 'id')):
+ print ' id="%s"' % row['id']
+ if (key_isprintable (row, 'start_time')):
+ print ' start="%s"' % time2npt (row['start_time'])
+ print '>'
+ if (key_isprintable (row, 'a_href')):
+ print '<a href="%(a_href)s">%(a_href)s</a>' % row
+
+ if (key_isprintable (row, 'img_src')):
+ print '<img src="%(img_src)s"/>' % row
+
+ if (key_isprintable (row, 'desc')):
+ print '<desc>%s</desc>' % escape(row['desc'])
+
+ print '</clip>'
+
print """
</cmml>
"""
@@ -140,7 +168,7 @@
ixp = get_ixp (path_info)
if (accept == "text/x-cmml"):
- fake_cmml(ixp)
+ make_cmml(ixp)
else:
anxenc (ixp, id, t)
--
conrad
More information about the cvs-annodex
mailing list