コード例 #1
0
ファイル: flickrupload.py プロジェクト: drewp/photo
    def POST(self):
        web.header('Content-type', 'application/json')
        i = web.input()
        uri = i['img']
        size = i.get('size', 'large')
        if size not in sizes:
            raise ValueError("size must be one of %r" % sizes.keys())

        log.info("fetch %s" % uri)
        tf = fetchImageToTempfile(uri, size, web.ctx.environ['HTTP_COOKIE'])

        log.info("connect to flickr")
        graph = getGraph()
        subj = PHO.flickrAccess

        flickr = flickrapi.FlickrAPI(graph.value(subj, PHO.key),
                                     graph.value(subj, PHO.secret))
        flickr.authenticate_console(perms='write')

        ret = {}
        if i.get('test', False):
            log.info("test mode: no upload")
            photoid = "12345"
            ret['test'] = True
        else:
            log.info("flickr.upload %r" % tf.name)
            newPhotos = flickr.upload(filename=tf.name,
                                title="bigasterisk upload",
                                description="",
                                tags="bigasterisk")
            assert newPhotos[0].tag == 'photoid'
            photoid = newPhotos[0].text
            
        ret['flickrUrl'] = 'http://www.flickr.com/photos/%s/%s' % (
            graph.value(subj, PHO.username), photoid)

        log.info("write rdf graph")

        writeStatements([
            (URIRef(uri), PHO.flickrCopy, URIRef(ret['flickrUrl'])),
            (URIRef(ret['flickrUrl']), DCTERMS.created, 
             Literal(iso8601.tostring(time.time(), timezone=time.altzone))),
            (URIRef(ret['flickrUrl']), DCTERMS.creator,
             URIRef(web.ctx.environ.get('HTTP_X_FOAF_AGENT',
                                        'http://example.com/unknown'))),
            ])


        return json.dumps(ret)
コード例 #2
0
    def postTagRange(self, ctx):
        # security?

        p = self.desc.photos()
        i1 = p.index(URIRef(ctx.arg('start')))
        i2 = p.index(URIRef(ctx.arg('end')))

        newUri = URIRef(ctx.arg('uri'))

        imgStatements = [(img, FOAF.depicts, newUri)
                         for img in p[i1:i2+1]]
        if (ctx.arg('label') or '').strip():
            imgStatements.append((newUri, RDFS.label, Literal(ctx.arg('label'))))
        writeStatements([
            (newUri, RDF.type, URIRef(ctx.arg('rdfClass'))),
            #(newUri, DC.created, Literal now
            ] + imgStatements)

        return json.dumps({
            "msg": "tagged %s images: <a href=\"%s\">view your new set</a>" %
            (len(imgStatements), newUri)
            })
コード例 #3
0
ファイル: imageSet.py プロジェクト: drewp/photo
    def postTagRange(self, ctx):
        # security?

        p = self.desc.photos()
        i1 = p.index(URIRef(ctx.arg('start')))
        i2 = p.index(URIRef(ctx.arg('end')))

        newUri = URIRef(ctx.arg('uri'))

        imgStatements = [(img, FOAF.depicts, newUri) for img in p[i1:i2 + 1]]
        if (ctx.arg('label') or '').strip():
            imgStatements.append(
                (newUri, RDFS.label, Literal(ctx.arg('label'))))
        writeStatements([
            (newUri, RDF.type, URIRef(ctx.arg('rdfClass'))),
            #(newUri, DC.created, Literal now
        ] + imgStatements)

        return json.dumps({
            "msg":
            "tagged %s images: <a href=\"%s\">view your new set</a>" %
            (len(imgStatements), newUri)
        })
コード例 #4
0
ファイル: access.py プロジェクト: drewp/photo
def makePublics(uris):
    writeStatements([(uri, PHO.viewableBy, PHO.friends) for uri in uris])
コード例 #5
0
ファイル: access.py プロジェクト: drewp/photo
def makePublics(uris):
    writeStatements([
        (uri, PHO.viewableBy, PHO.friends) for uri in uris
        ])