Exemplo n.º 1
0
def main():
    graph = getGraph()
    graph.query = graph.queryd
    index = ImageIndex(graph)
    iset = ImageSet(graph, index)

    @route('/update', methods=['POST'])
    def update(request):
        log.info('updating %r', request.args)
        index.update(URIRef(request.args['uri'][0]))
        log.info('done updating')
        # schedule updateSorts? maybe they need to schedule themselves
        return 'indexed'
    
    @route('/set.json')
    def main(request):
        pairs = []
        for k, vs in request.args.items():
            for v in vs:
                pairs.append((k, v))
        q = queryFromParams(pairs)
        result = iset.request(q)
        return json.dumps(result)

    run("0.0.0.0", networking.imageSet()[1])
Exemplo n.º 2
0
    def __init__(self):

        pool = Pool(processes=2)
        self.graph = getGraph()

        files = findFiles(opts)

        self.progressQueue = Queue()
        reporter = Process(target=ProgressReport,
                           args=(self.progressQueue, len(files)))
        reporter.start()
        result = pool.map(self.cacheFile, enumerate(files), chunksize=5)
        self.progressQueue.put('END')
        log.info("finished, %s results", len(result))
        reporter.join()
Exemplo n.º 3
0
    def __init__(self):

        pool = Pool(processes=2)
        self.graph = getGraph()

        files = findFiles(opts)

        self.progressQueue = Queue()
        reporter = Process(target=ProgressReport,
                           args=(self.progressQueue, len(files)))
        reporter.start()
        result = pool.map(self.cacheFile, enumerate(files), chunksize=5)
        self.progressQueue.put('END')
        log.info("finished, %s results", len(result))
        reporter.join()
Exemplo n.º 4
0
def main():
    graph = getGraph()
    graph.query = graph.queryd
    index = ImageIndex(graph)
    iset = ImageSet(graph, index)

    @route('/update', methods=['POST'])
    def update(request):
        log.info('updating %r', request.args)
        index.update(URIRef(request.args['uri'][0]))
        log.info('done updating')
        # schedule updateSorts? maybe they need to schedule themselves
        return 'indexed'

    @route('/created', methods=['GET'])
    def created(request):
        def tOut(uri):
            t = index.byUri[uri]['t']
            if t is None:
                return 'None'
            return t.isoformat()

        return '\n'.join(tOut(URIRef(uri)) for uri in request.args['uri'])

    @route('/set.json')
    def main(request):
        pairs = []
        for k, vs in request.args.items():
            for v in vs:
                pairs.append((k, v))
        q = queryFromParams(pairs)
        t1 = time.time()
        result = iset.request(q)
        log.info('iset.request in %.1f ms', 1000 * (time.time() - t1))
        return json.dumps(result)

    run("0.0.0.0", networking.imageSet()[1])
Exemplo n.º 5
0
            stmts.append((newAltUri, PHO[k], Literal(v)))

    graph.add(stmts, context=ctx)
    return "added %s statements to context %s" % (len(stmts), ctx)

def pickNewUri(self, uri, tag):
    for suffix in itertools.count(1):
        proposed = URIRef("%s/alt/%s%s" % (uri, tag, suffix))
        if not graph.contains((proposed, None, None)):
            return proposed
                


def personAgeString(isoBirthday, photoDate):
    try:
        sec = iso8601.parse(str(photoDate))
    except Exception:
        sec = iso8601.parse(str(photoDate) + '-0700')

    birth = iso8601.parse(isoBirthday)
    days = (sec - birth) / 86400
    if days / 30 < 12:
        return "%.1f months" % (days / 30)
    else:
        return "%.1f years" % (days / 365)

if __name__ == '__main__':
    graph = db.getGraph()
    run('0.0.0.0', networking.oneImageServer()[1])

Exemplo n.º 6
0
        picUri = scanFs.fileChanged(filename)
        log.info('picUri is %r', picUri)
        if picUri is not None:
            # this will fail on videos (though i wish i could get the Pre metadata out of them)
            scanExif.addPic(picUri, rerunScans=True)
            mr = MediaResource(graph, picUri)
            if mr.isVideo():
                mr.videoProgress()
            # todo: freshen thumbs here too? that should be on a lower
            # priority queue than getting the exif/file data
            v2.imageset.client.changed(picUri)


quick = False

graph = getGraph()

scanFs = ScanFs(graph, '/my/pic')
scanExif = ScanExif(graph)

syncs = {}
subdirs = picSubDirs(
    syncs, SesameSync, graph,
    quick)  # root directories for fileschanged to watch underneath

if quick:
    onChange('/my/site/photo/input/local.n3')
    onChange('/my/pic/flickr/3716645105_27bca1ba5a_o.jpg')
    onChange('/my/pic/phonecam/dt-2009-07-16/CIMG0074.jpg')
    onChange('/my/pic/digicam/dl-2009-07-20/DSC_0092.JPG')
Exemplo n.º 7
0
import sys
from klein import run, route
import json
sys.path.append("../..")
from db import getGraph
import auth

graph = getGraph()

@route('/allTags')
def allTags(request):
    tags = set()
    for row in graph.queryd(
            "SELECT ?tag WHERE { ?pic scot:hasTag [ rdfs:label ?tag ] }"):
        tag = unicode(row['tag'])
        if tag in auth.hiddenTags:
            continue
        tags.add(tag)
    tags = sorted(tags)
    return json.dumps({'tags': tags})

if __name__ == '__main__':
    run("0.0.0.0", 8054)
Exemplo n.º 8
0
import logging

logging.basicConfig()
import unittest
from db import getGraph
from imageurl import ImageSetDesc
from ns import SITE

logging.getLogger('restkit.client').setLevel(logging.WARN)

graph1 = getGraph()


class TestImageSetDesc(unittest.TestCase):
    def testCanonicalOmitsCurrentParam(self):
        s = ImageSetDesc(graph1, None, "/set?tag=t&current=foo")
        self.assertEqual(s.canonicalSetUri(), SITE["set?tag=t"])

    def testCanonicalIncludesDirParam(self):
        s = ImageSetDesc(graph1, None,
                         "/set?dir=http%3A%2F%2Fexample.com%2Fd1&current=foo")
        self.assertEqual(s.canonicalSetUri(),
                         SITE["set?dir=http%3A%2F%2Fexample.com%2Fd1"])

    def testCanonicalIncludesStarParam(self):
        s = ImageSetDesc(graph1, None,
                         "/set?dir=http%3A%2F%2Fexample.com%2Fd1&star=only")
        self.assertEqual(
            s.canonicalSetUri(),
            SITE["set?dir=http%3A%2F%2Fexample.com%2Fd1&star=only"])
Exemplo n.º 9
0
?pic wgs:location [ wgs:lat ?lat ; wgs:long ?long ]
        FILTER (?lat > ?lat1 && ?lat < ?lat2 && ?long > ?long1 && ?long < ?long2 )
        }""",
                            initBindings=bindings)
        print "%s -> %s rows in %s" % (bindings, len(rows), time.time() - t1)
        if len(rows) > 200:
            random.shuffle(rows)
            print "reducing"
            rows = rows[:200]
        # or two pics at same point should make a cluster too
        self.write({
            'markers': [
                dict(uri=row['pic'], lat=row['lat'], long=row['long'])
                for row in rows
            ]
        })


if __name__ == '__main__':
    reactor.listenTCP(
        9088,
        cyclone.web.Application(handlers=[
            (r"/(|gui.js)", cyclone.web.StaticFileHandler, {
                'path': '.',
                'default_filename': 'index.html'
            }),
            (r'/photos', Photos),
        ],
                                graph=db.getGraph()))
    reactor.run()
Exemplo n.º 10
0
from arango import ArangoClient

import db

if __name__ == "__main__":
    authoring_graph = db.getGraph("authoring")
    user_col = db.getVertexCollection(authoring_graph, "v2_users")
    tweets_col = db.getVertexCollection(authoring_graph, "v2_tweets")
    authoring_col = db.getEdgeDefinition(authoring_graph, "v2_authoring",
                                         ["v2_users"], ["v2_tweets"])
    # user_col.insert({'_key': 'user1', 'screen_name': 'User1'})
    # user_col.insert({'_key': 'user2', 'screen_name': 'User2'})
    # tweets_col.insert({'_key': 'tweet1', 'text': 't1'})
    # tweets_col.insert({'_key': 'tweet2', 'text': 't2'})
    authoring_col.insert({
        '_key': '13421322',
        '_to': 'v2_tweets/tweet2',
        '_from': 'v2_users/user2'
    })
    authoring_col.insert({
        '_key': '13421321',
        '_to': 'v2_tweets/tweet1',
        '_from': 'v2_users/user1'
    })
Exemplo n.º 11
0
            long2=SparqlFloat(max(float(arg("e")), float(arg("w")))),
        )
        rows = graph.queryd("""
PREFIX wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
SELECT DISTINCT ?pic ?lat ?long WHERE { 
?pic wgs:location [ wgs:lat ?lat ; wgs:long ?long ]
        FILTER (?lat > ?lat1 && ?lat < ?lat2 && ?long > ?long1 && ?long < ?long2 )
        }""", initBindings=bindings)
        print "%s -> %s rows in %s" % (bindings, len(rows), time.time() - t1)
        if len(rows) > 200:
            random.shuffle(rows)
            print "reducing"
            rows = rows[:200]
        # or two pics at same point should make a cluster too
        self.write({'markers':
                    [dict(uri=row['pic'], 
                          lat=row['lat'], 
                          long=row['long']) 
                     for row in rows]})


if __name__ == '__main__':
    reactor.listenTCP(
        9088, cyclone.web.Application(handlers=[
            (r"/(|gui.js)", cyclone.web.StaticFileHandler, {
                'path': '.', 'default_filename': 'index.html'
            }),
            (r'/photos', Photos),
        ], graph=db.getGraph()))
    reactor.run()
Exemplo n.º 12
0
import logging
logging.basicConfig()
import unittest
from db import getGraph
from imageurl import ImageSetDesc
from ns import SITE
logging.getLogger('restkit.client').setLevel(logging.WARN)

graph1 = getGraph()

class TestImageSetDesc(unittest.TestCase):
    def testCanonicalOmitsCurrentParam(self):
        s = ImageSetDesc(graph1, None, "/set?tag=t&current=foo")
        self.assertEqual(s.canonicalSetUri(), SITE["set?tag=t"])

    def testCanonicalIncludesDirParam(self):
        s = ImageSetDesc(graph1, None, "/set?dir=http%3A%2F%2Fexample.com%2Fd1&current=foo")
        self.assertEqual(s.canonicalSetUri(), SITE["set?dir=http%3A%2F%2Fexample.com%2Fd1"])

    def testCanonicalIncludesStarParam(self):
        s = ImageSetDesc(graph1, None, "/set?dir=http%3A%2F%2Fexample.com%2Fd1&star=only")
        self.assertEqual(s.canonicalSetUri(), SITE["set?dir=http%3A%2F%2Fexample.com%2Fd1&star=only"])

    def testCanonicalIncludesDateParam(self):
        s = ImageSetDesc(graph1, None, "/set?date=2010-11-20")
        self.assertEqual(s.canonicalSetUri(), SITE["set?date=2010-11-20"])

    def testCanonicalErrorsOnRandomParam(self):
        s = ImageSetDesc(graph1, None, "/set?random=10")
        self.assertRaises(ValueError, s.canonicalSetUri)