Beispiel #1
0
    def __init__(self, crumbs, root, channel, timeprefix, selfuri):
        EventSink.__init__(self, root, channel, timeprefix, selfuri)

        self.crumbs = crumbs

        self.title = "#%s on %s" % (channel, timeprefix)

        self.context = context = new_context()
        context.addGlobal('crumbs', self.crumbs)
        context.addGlobal('datarooturi', self.root)
        context.addGlobal('datauri', self.datauri)
Beispiel #2
0
def html_index(sink, crumbs, root, datauri, querychannel):
    context = new_context()
    context.addGlobal('crumbs', crumbs)
    context.addGlobal('datarooturi', root)
    context.addGlobal('datauri', datauri)

    context.addGlobal('querychannel', querychannel)

    channels = sorted(sink.channels.keys())

    if querychannel:
        title = "Channel #%s" % channels[0]
    else:
        title = "Some IRC discussion logs"

    context.addGlobal('title', title)

    if datauri == root:
        datauri2 = root + "index"
    else:
        datauri2 = datauri

    context.addGlobal('datauri2', datauri2)

    channeldata = []
    for channel in channels:
        channelID = channel.strip("#").lower()
        channelURI = root + channelID + "#channel"
        channeldata.append({'uri': channelURI, 'name': channelID})

    # XXX list works around a bug in simpletal
    days = list(reversed(sorted(sink.days.keys())))

    context.addGlobal('channels', channeldata)
    context.addGlobal('days', days)
    context.addGlobal('day2channels', sink.day2channels)

    if querychannel:
        nicks = sorted(sink.channel2nicks[querychannel].keys())
    else:
        nicks = sorted(sink.nicks)

    userdata = []
    for nick in nicks:
        userURI = root + "users/%s#user" % nick
        userdata.append({'uri': userURI, 'name': nick})
    context.addGlobal('users', userdata)
    context.addGlobal('nick2people', get_nick2people())

    template = get_template('index')
    expand_template(template, context)
Beispiel #3
0
def render_user_index(sink, format, crumbs, datarooturi, datauri):
    freenodeURI = datarooturi + "#freenode"
    nicks = get_nicks()
    nick2people = get_nick2people()
    if format == "html":
        context = new_context()
        context.addGlobal('crumbs', crumbs)
        context.addGlobal('datarooturi', datarooturi)
        context.addGlobal('datauri', datauri)

        users = []
        for nick in nicks:
            user = datarooturi + "users/%s#user" % nick
            users.append({'uri': user, 'nick': nick})

        context.addGlobal('users', users)

        template = get_template('users')
        expand_template(template, context)

    elif format == "turtle":
        triples = []
        for nick in nicks:
            user = datarooturi + "users/%s#user" % nick
            triples += [None,
                        (freenodeURI, SIOC.space_of, user),
                        (user, RDFS.label, PlainLiteral(nick)),
                        (user, RDF.type, SIOC.User)]
            if nick in nick2people:
                triples += [(nick2people[nick], FOAF.holdsAccount, user)]

        writer = TurtleWriter(None, namespaces)
        title = "User index"
        writer.write([("", RDFS.label, PlainLiteral(title)),
                      ("", FOAF.primaryTopic, freenodeURI)])
        writer.write(triples)
        writer.close()
Beispiel #4
0
def render_user(sink, format, crumbs, datarooturi, nick, datauri, latestsink):
    userURI = datarooturi + "users/%s#user" % nick

    global Red
    import RDF as Red

    person = find_person(nick)

    error = None

    model = Red.Model()
    # XXX work around a bug in Redland?
    if person:
        try:
            model.load(person.rsplit('#', 1)[0], name='guess')
        except:
            error = "Error loading the FOAF info: %s" % sys.exc_info()[1]

    channels = sorted(sink.nick2channels.get(nick, {}).keys())

    if format == "html":
        context = new_context()
        context.addGlobal('crumbs', crumbs)
        context.addGlobal('datarooturi', datarooturi)
        context.addGlobal('datauri', datauri)
        context.addGlobal('error', error)

        info = []
        if person:
            for name in link_values(model, person, [FOAF.name, FOAF.firstName, FOAF.nick, RDFS.label]):
                info.append({'key': 'Name', 'value': "%s" % name})
            for ircnick in nick_values(datarooturi, model, person, [FOAF.holdsAccount]):
                if userURI in ("%s" % ircnick):
                    ircnick = ircnick + " <em>[confirms the Web ID claim]</em>"
                elif ircnick is None:
                    ircnick = """None <em>[can't confirm the Web ID claim, should be <a href="%s">%s</a>]</em>""" % (userURI, nick)
                else:
                    ircnick = ircnick + """ <em>[doesn't confirm the Web ID claim, should be <a href="%s">%s</a>]</em>""" % (userURI, nick)
                info.append({'key': 'IRC account', 'value': "%s" % ircnick})
            for website in link_values(model, person, [FOAF.homepage]):
                info.append({'key': 'Website', 'value': "%s" % website})
            for weblog in link_values(model, person, [FOAF.weblog]):
                info.append({'key': 'Weblog', 'value': "%s" % weblog})
            for img in image_values(model, person, [FOAF.depiction, FOAF.img]):
                info.append({'key': 'Image', 'value': "%s" % img})
            for known in friend_values(datarooturi, model, person, [FOAF.knows]):
                info.append({'key': 'Knows', 'value': "%s" % known})

        context.addGlobal('here', {'nick': nick,
                                   'person': {'webid': person,
                                              'info': info}})

        channeldata = []
        for channel in channels:
            channelURI = datarooturi + "%s#channel" % channel
            channeldata.append({'uri': channelURI, 'name': "#"+channel})
        context.addGlobal('channels', channeldata)

        context.addGlobal('events', latestsink.events)

        template = get_template('user')
        expand_template(template, context)

    elif format == "turtle":
        oldUserURI = "irc://freenode/%s,isuser" % nick
        triples = [None,
                   (datarooturi + "#freenode", SIOC.space_of, userURI),
                   (userURI, OWL.sameAs, oldUserURI),
                   (userURI, RDFS.label, PlainLiteral(nick)),
                   (userURI, RDF.type, SIOC.User),
                   ]
        if person:
            triples += [None, (person, FOAF.holdsAccount, userURI)]
            triples += get_triples(model, person, [FOAF.name, FOAF.firstName, FOAF.nick, RDFS.label])
        for channel in channels:
            channelURI = datarooturi +  "%s#channel" % channel
            triples += [None, 
                        (channelURI, SIOC.has_subscriber, userURI),
                        (channelURI, RDFS.label, PlainLiteral("#%s" % channel)),
                        ]
        writer = TurtleWriter(None, namespaces)
        title = "About user %s" % nick
        writer.write([("", RDFS.label, PlainLiteral(title)),
                      ("", FOAF.primaryTopic, userURI),
                      ])
        writer.write(triples)
        writer.close()