def run(self): ret = query(""" SELECT ?a WHERE { <http://www.lemonde.fr/> <http://activearchives.org/terms/annotation> ?a . }""", RDF_MODEL) foo = [] for i in ret: foo.append("<section class='section2'>%s</section>" % str(i['a'])) return "".join(foo)
def run(self): ret = query("""\ SELECT DISTINCT ?url ?title WHERE { ?url <http://www.w3.org/1999/xhtml/vocab#index> ?c. ?url <http://purl.org/dc/elements/1.1/title> ?title. }""", RDF_MODEL) foo = ["<ul>"] for i in ret: path = urlparse(str(i['url'])).path foo.append('<li><a href="%s">%s</a></li>' % (path, str(i['title']))) foo.append("</ul>") return "".join(foo)
def run(self): embed_style = None if self.arguments: embed_style = self.arguments else: q = dedent("""\ PREFIX dc:<http://purl.org/dc/elements/1.1/> PREFIX aa:<http://activearchives.org/terms/> PREFIX http:<http://www.w3.org/Protocols/rfc2616/> PREFIX media:<http://search.yahoo.com/mrss/> SELECT ?ctype ?format ?audiocodec ?videocodec WHERE {{ OPTIONAL {{ <%(URL)s> http:content_type ?ctype . }} OPTIONAL {{ <%(URL)s> dc:format ?format . }} OPTIONAL {{ <%(URL)s> media:audio_codec ?audiocodec . }} OPTIONAL {{ <%(URL)s> media:video_codec ?videocodec . }} }}""".strip() % {'URL': self.stdin['original_url']}) b = {} for row in rdfutils.query(q, RDF_MODEL): for name in row: b[name] = rdfutils.rdfnode(row.get(name)) break # TODO: move to templates if b.get('ctype') in ("image/jpeg", "image/png", "image/gif"): embed_style = "img" elif b.get('ctype') in ("video/ogg", "video/webm") or (b.get('videocodec') in ("theora", "vp8")): embed_style = "html5video" elif b.get('ctype') in ("audio/ogg", ) or (b.get('audiocodec') == "vorbis" and (not b.get('videocodec'))): embed_style = "html5audio" elif b.get('ctype') in ("text/html", ): embed_style = "iframe" elif b.get('ctype') in ("application/rss+xml", "text/xml", "application/atom+xml"): embed_style = "feed" else: embed_style = None # TODO: move to templates if embed_style == "img": self.stdout['output'] = '<img src="%s" />' % self.stdin['original_url'] elif embed_style == "html5video": #self.stdout['output'] = '<video class="player" controls src="%s" />' % self.stdin['local_url'] # Temporarily fixes the local serveur serving ogg with the wronf mimetype self.stdout['output'] = '<video class="player" controls src="%s" />' % self.stdin['original_url'] elif embed_style == "html5audio": #self.stdout['output'] = '<audio class="player" controls src="%s" />' % self.stdin['local_url'] # Temporarily fixes the local serveur serving ogg with the wronf mimetype self.stdout['output'] = '<audio class="player" controls src="%s" />' % self.stdin['original_url'] elif embed_style == "iframe": self.stdout['output'] = '<iframe src="%s"></iframe>' % self.stdin['local_url'] elif embed_style == "feed": feed = feedparser.parse(self.stdin['local_url']) self.stdout['output'] = u'' for entry in feed['entries'][:4]: self.stdout['output'] += u'<div>' self.stdout['output'] += u'<h3><a href="%s">%s</a></h3>' % (entry.link, entry.title) self.stdout['output'] += u'<div>' self.stdout['output'] += entry.summary self.stdout['output'] += u'</div>' self.stdout['output'] += u'</div>' else: self.stdout['output'] = "<p>Unable to detect embed type</p>"