コード例 #1
0
ファイル: pyshareflow.py プロジェクト: zenbe/pyshareflow
    def _add_time_params(self, query, order_by, before, after):
        # TODO Allow inclusive, exclusive
        time_param = {}

        if before:
            time_param.update({'<': iso8601.tostring(before)})

        if after:
            time_param.update({'>' : iso8601.tostring(after)})

        if len(time_param) > 0:
            if order_by == 'updated':
                query.updated_at = time_param
            else:
                query.created_at = time_param
コード例 #2
0
ファイル: map2.py プロジェクト: drewp/maps
class history(object):
    def GET(self):
        web.header('Content-type', 'application/xhtml+xml; charset=UTF-8')

        rows = mongo.find().sort([("timestamp", -1)]).limit(50)

        def closest(row):
            return describeLocation(
                row['longitude'], row['latitude'],
                row.get('horizAccuracy', row.get('accuracy', 0)), row['user'])
            try:
                name, meters = closestTarget(row['longitude'], row['latitude'],
                                             row['user'])
            except ValueError, e:
                return 'err (%s)' % e
            if meters > 900:
                dist = "%.3f miles" % (meters * milesPerMeter)
            else:
                dist = "%d m" % meters

            return "%s (%s)" % (name, dist)

        return render.history(
            rows=rows,
            prettyTime=lambda milli: iso8601.tostring(
                milli / 1000,
                time.altzone  # wrong
            ).replace('T', ' '),
            foafName=foafName,
            placeName=placeName,
            closest=closest,
        )
コード例 #3
0
ファイル: timejunk.py プロジェクト: drewp/traintimes
def literalFromTime(secs='now'):
    if secs == 'now':
        secs = time.time()
    # wrong formatting for :00 seconds, i think.
    # timezone may be wrong too :(
    i = iso8601.tostring(secs, [time.timezone, time.altzone][time.daylight])
    return Literal(i, datatype=XS['dateTime'])
コード例 #4
0
def literalFromTime(secs='now'):
    if secs == 'now':
        secs = time.time()
    # wrong formatting for :00 seconds, i think.
    # timezone may be wrong too :(
    i = iso8601.tostring(secs, [time.timezone, time.altzone][time.daylight])
    return Literal(i, datatype=XS['dateTime'])
コード例 #5
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)
コード例 #6
0
def saveTags(graph, foafUser, img, tagString, desc):
    global _twf
    if not allowedToWrite(graph, foafUser):
        raise ValueError("not allowed")
    _twf = None 
    
    subgraph = URIRef('http://photo.bigasterisk.com/update/%f' %
                      time.time())
    stmts = set([
        (subgraph, DCTERMS.creator, foafUser),
        (subgraph, DCTERMS.created,
         Literal(iso8601.tostring(time.time(), timezone=time.altzone))),
        (img, PHO.tagString, Literal(tagString)),
        (img, RDFS.comment, Literal(desc)),
        ])
    log.info('save tags %r', stmts)
    tagDefs = set()
    for w in tagString.split():
        # need to trim bad url chars and whatever else we're not going to allow
        tag = URIRef('http://photo.bigasterisk.com/tag/%s' % w)
        stmts.add((img, SCOT.hasTag, tag))
        tagDefs.add((tag, RDFS.label, Literal(w)))
        tagDefs.add((tag, RDF.type, SCOT.Tag))
        tagDefs.add((tag, SCOT.usedBy, foafUser)) # derivable from the subgraph

    prevContexts = [row['g'] for row in graph.queryd(
        "SELECT ?g WHERE { GRAPH ?g { ?img pho:tagString ?any } }",
        initBindings={Variable("img") : img})]
        
    graph.add(stmts, context=subgraph)
    log.info("Wrote tag data to %s" % subgraph)
    graph.add(tagDefs, context=URIRef('http://photo.bigasterisk.com/tagDefs'))

    for c in prevContexts:
        graph.remove([(None, None, None)], context=c)
    v2.imageset.client.changed(img)
コード例 #7
0
ファイル: commandpage.py プロジェクト: drewp/magma
    def child_addCommand(self, ctx):


        # this is obsoleted by a magma/addCommand handler

        
        request = inevow.IRequest(ctx)
        if request.method != "POST":
            # there's a correct http status for this
            raise ValueError("addCommand only takes POST")

        # nevow has a better form than this, i hope
        request.content.seek(0)
        args = dict(url.unquerify(request.content.read()))

        t = iso8601.tostring(float(args.get('time', time.time())),
                             # using current timezone, even for passed-in value
                             (time.timezone, time.altzone)[time.daylight]) 
        user = URIRef(args.get('user', 'http://bigasterisk.com/magma/user_tbd'))
        self.cmdlog.addCommand(URIRef(args['uri']),
                               Literal(t, datatype=XS['dateTime']),
                               user)

        return url.URL.fromString('http://bigasterisk.com/magma/heater/')# TODO#returnPage("text/javascript",
コード例 #8
0
ファイル: myplistlib.py プロジェクト: alikins/crate
    def toString(self):
        from xml.utils.iso8601 import tostring

        return tostring(self.date)
コード例 #9
0
ファイル: myplistlib.py プロジェクト: pombredanne/crate-2
 def toString(self):
     from xml.utils.iso8601 import tostring
     return tostring(self.date)
コード例 #10
0
ファイル: diarybot.py プロジェクト: drewp/diarybot
def literalFromUnix(t):
    return Literal(iso8601.tostring(t, time.altzone), # todo: timezones
                   datatype=XS.dateTime)