Commits

Uche Ogbuji committed 55fa3a5

FIxes to Balisage demos

  • Participants
  • Parent commits dc5a612

Comments (0)

Files changed (3)

File balisage09/schedule.py

 #25 lines to scrape Balisage schedule and generate tweets (including a URL shortener)
+#Note: performance almost entirely based on speed of access to the URL shortener service
+#Usage:
+#curl http://www.balisage.net/2009/At-A-Glance.html | python schedule.py 
 import sys, urllib, urllib2
 from amara.bindery import html
 from amara.lib import iri
 
 BASE = 'http://www.balisage.net/2009/At-A-Glance.html'
 SUFFIX = '#balisage2009'
-SHORTENER = 'http://ur1.ca/'
+URL_SHORTENER = 'http://ur1.ca/'
 
 doc = html.parse(sys.stdin)
 abstracts = doc.xml_select(u'//a[@class="abstract"]')
 def shorten_url(url):
     params = {'longurl': url}
     data = urllib.urlencode(params)
-    request = urllib2.Request(SHORTENER, data)
+    request = urllib2.Request(URL_SHORTENER, data)
     resultdoc = html.parse(urllib2.urlopen(request).read())
     shortened = resultdoc.xml_select(u'string(//p[@class="success"]/a)')
     return shortened
 
 for ab in abstracts:
-    bits = []
+    chunks = []
     #Many other ways to do this but wanted to demo XPath fullnes :)
-    bits.append('"'+unicode(ab)+'"')
-    bits.append(ab.xml_select(u'string(following-sibling::*//a[@class="biolink"])'))
-    bits.append(shorten_url(iri.absolutize(ab.href, BASE)))
-    bits.append(SUFFIX)
-    msg = ' '.join(bits)
+    chunks.append('"'+unicode(ab)+'"')
+    chunks.append(ab.xml_select(u'string(following-sibling::*//a[@class="biolink"])'))
+    chunks.append(shorten_url(iri.absolutize(ab.href, BASE)))
+    chunks.append(SUFFIX)
+    msg = ' '.join(chunks)
     print msg
-    print len(msg)
+    print 'Length:', len(msg)
 

File balisage09/slide31.py

-MODEL_A = '''<labels xmlns:eg="http://examplotron.org/0/" xmlns:ak="http://purl.org/dc/org/xml3k/akara">
+MODEL_A = '''<labels xmlns:eg="http://examplotron.org/0/" xmlns:ak="http://purl.org/xml3k/akara/xmlmodel">
   <label id="tse" added="2003-06-10" eg:occurs="*" ak:resource="@id">
     <!-- use ak:resource="" for an anonymous resource -->
     <quote eg:occurs="?">
     <tag eg:occurs="*" ak:rel="name()">old possum</tag>
   </label>
 </labels>
-'''
+'''
 labelmodel = examplotron_model(MODEL_A)
 
 INSTANCE_A_1 = '''<labels>

File balisage09/slide33.py

 
 @simple_service('GET', ECOUNTER_SERVICE_ID, 'ecounter', 'text/plain')
 def ecounter(uri):
-    #e.g.: curl http://localhost:8880/akara.xslt?http://hg.akara.info/testdoc.xml"
+    #e.g.: curl http://localhost:8880/ecounter?uri=http://hg.akara.info/testdoc.xml"
     uri = inputsource(uri[0], resolver=restricted_resolver)
     doc = amara.parse(uri)
     ecount = doc.xml_select(u'count(//*)')