#!/usr/bin/python __author__ = "Mark Pilgrim (mark@diveintomark.org)" __copyright__ = "Copyright 2002, Mark Pilgrim" __license__ = "GPL" __version__ = "1.0" __cvsversion__ = "$Revision: 1.1 $"[11:-2] __date__ = "$Date: 2002/11/17 02:52:38 $"[7:-2] from rdflib.TripleStore import TripleStore # http://rdflib.net/ from rdflib import URIRef from rdf.sir import Namespace FOAFFILE = 'http://diveintomark.org/public/foaf.rdf' ID = 'mark' store = None foaf = Namespace('http://xmlns.com/foaf/0.1/') dc = Namespace('http://purl.org/dc/elements/1.1/') title = dc['title'] description = dc['description'] def load(): global store store = TripleStore() store.load(FOAFFILE) def mget(subject, predicate): return [s for s in store.objects(subject, predicate)] def get(subject, predicate): data = [s for s in store.objects(subject, predicate)] if data: return data[0] else: return None def link(subject, includeDescription=1): linkvalue = get(subject, title) if includeDescription: linkdescription = get(subject, description) else: linkdescription = None return """%s%s""" % (subject, linkvalue, linkdescription and (", %s" % linkdescription) or "") def main(): load() my = Namespace(FOAFFILE + "#" + ID) print "
My name is %s," % get(my, foaf['name']), print "and this is %s." % link(get(my, foaf['homepage'])), print "Here I write about whatever happens to interest me. At the moment, this includes things like ", print ", ".join(map(link, mget(my, foaf['interest'])[:-1])) + ", and %s.
" % link(mget(my, foaf['interest'])[-1]) print "I work for %s." % link(get(my, foaf['workplaceHomepage'])), print "Nothing on %s" % link(get(my, foaf['homepage']), 0), print "is affiliated with, sponsored by, or endorsed by %s.
" % (link(get(my, foaf['workplaceHomepage']), 0)) print "You can also find my digital footprints elsewhere:
" print "You may contact me at %s.
""" % (email, email.split(':', 1)[1]) img = get(my, foaf['depiction']) imgalt = get(img, description) imgtitle = get(img, title) print """