Exemple #1
0
import web, json, socket
from twisted.python.util import sibpath
from light9.namespaces import L9
from light9.showconfig import getSongsFromShow, songOnDisk
from rdflib import URIRef
from web.contrib.template import render_genshi
render = render_genshi([sibpath(__file__, ".")])
app = None


_songUris = {} # locationUri : song
def songLocation(graph, songUri):
    loc = URIRef("file://%s" % songOnDisk(songUri))
    _songUris[loc] = songUri
    return loc
    
def songUri(graph, locationUri):
    return _songUris[locationUri]

class root(object):
    def GET(self):
        web.header("Content-type", "application/xhtml+xml")
        # todo: use a template; embed the show name and the intro/post
        # times into the page
        return render.index(host=socket.gethostname())

class timeResource(object):
    def GET(self):
        player = app.player
        graph = app.graph
Exemple #2
0
#!/usr/bin/python
"""
display diary entries
"""
import sys, web, restkit
from web.contrib.template import render_genshi
from rdflib import URIRef
sys.path.append(".")
from diarybot import RdfStore
import xml.utils.iso8601
import datetime
render = render_genshi('.', auto_reload=True)

def getLoginBar():
    openidProxy = restkit.Resource("http://bang:9023/")
    return openidProxy.get("_loginBar",
                 headers={"Cookie" : web.ctx.environ.get('HTTP_COOKIE', '')})

urls = (r'/', "index",
        )

app = web.application(urls, globals(), autoreload=True)
application = app.wsgifunc()

class index(object):
    def GET(self):
        web.header('Content-type', 'application/xhtml+xml')

        agent = URIRef(web.ctx.environ['HTTP_X_FOAF_AGENT'])
        # todo- look up available bot uris for this agent
        store = RdfStore(bot)
Exemple #3
0
import web
from web.contrib import template

render = template.render_genshi(['./templates/'])

urls = (
    '/', 'index'
)

class index:
    def GET(self):
        #i = web.input(name=None)
        name = 'Bob'
        return render.index(name=name)


if __name__ =="__main__":
    app = web.application(urls, globals())
    app.run()
Exemple #4
0
import sys, web, time, jsonlib, logging, datetime, os, json, re
from xml.utils import iso8601
from dateutil.tz import tzlocal
from web.contrib.template import render_genshi
from pyproj import Geod  # geopy can do distances too
import restkit
from pymongo import Connection, DESCENDING
from locations import readGoogleMapsLocations

logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger()
milesPerMeter = 0.000621371192237334

config = json.loads(open("priv.json").read())

render = render_genshi('templates', auto_reload=True)

urls = (
    r'/',
    'index',
    r'/history',
    'history',
    r'/update',
    'update',
    r'/logPos.php',
    'update',
    r'/gmap',
    'gmap',
    r'/drawMap.png',
    'drawMapImg',
    r'/updateTrails',
Exemple #5
0
#!/usr/bin/python
"""
web app to query an elasticsearch database, edit mpd playlist
"""

import restkit, jsonlib, logging, web
from web.contrib.template import render_genshi
logging.basicConfig()
log = logging.getLogger()

render = render_genshi('.', auto_reload=True)

elastic = restkit.Resource("http://plus:9200/")

urls = (
    r"/",
    "index",
    r"/search",
    "search",
    r"/jquery-1.4.2.min.js",
    "jquery",
)


class index(object):
    def GET(self):
        web.header("Content-Type", "application/xhtml+xml")
        return render.searchelastic()


class search(object):
Exemple #6
0
import sys, os, datetime, cyclone.web, simplejson, logging, cgi, time
sys.path.extend(["../f/FuXi-1.2.production/build/lib.linux-x86_64-2.6",
                 "/my/proj/room/fuxi/build/lib.linux-x86_64-2.6/"])
from twisted.internet import reactor, defer
from twisted.web.client import getPage
from twisted.python import log
from rdflib.Graph import ConjunctiveGraph
from rdflib import Namespace, Literal, URIRef, RDFS, RDF
sys.path.extend(["/my/proj/homeauto/service/reasoning"])
from inference import parseTrig
sys.path.extend(["../../ffg/ffg", '/my/proj/ffg/ffg'])
from evtiming import logTime
from web.contrib.template import render_genshi

logging.basicConfig(level=logging.DEBUG)
render = render_genshi(os.path.dirname(__file__), auto_reload=True)

DEV = Namespace("http://projects.bigasterisk.com/device/")
ROOM = Namespace("http://projects.bigasterisk.com/room/")
CL = Namespace("http://bigasterisk.com/ns/command/v1#")

def linked(txt, uri):
    if not txt:
        txt = uri
    ret = cgi.escape(txt)
    if uri:
        ret = '<a href="%s">%s</a>' % (cgi.escape(uri), ret)
    return ret

def readGraphs():
    g = ConjunctiveGraph()
Exemple #7
0
import sys, web, time, jsonlib, logging, datetime, os, json, re
from xml.utils import iso8601
from dateutil.tz import tzlocal
from web.contrib.template import render_genshi
from pyproj import Geod # geopy can do distances too
import restkit
from pymongo import Connection, DESCENDING
from locations import readGoogleMapsLocations

logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger()
milesPerMeter = 0.000621371192237334

config = json.loads(open("priv.json").read())

render = render_genshi('templates', auto_reload=True)

urls = (r'/', 'index',
        r'/history', 'history',
        r'/update', 'update',
        r'/logPos.php', 'update',
        r'/gmap', 'gmap',
        r'/drawMap.png', 'drawMapImg',
        r'/updateTrails', 'updateTrails',
        )

app = web.application(urls, globals(), autoreload=False)
m = config['mongo']
mongo = Connection(m['host'], m['port'])[m['db']][m['collection']]
makeTime = lambda milli: datetime.datetime.fromtimestamp(milli/1000, tzlocal()).isoformat()
Exemple #8
0
import json, socket, subprocess, cyclone.web, os
from twisted.python.util import sibpath
from twisted.python.filepath import FilePath
from light9.namespaces import L9
from light9.showconfig import getSongsFromShow, songOnDisk
from rdflib import URIRef
from web.contrib.template import render_genshi
render = render_genshi([sibpath(__file__, ".")], auto_reload=True)

from lib.cycloneerr import PrettyErrorHandler

_songUris = {} # locationUri : song
def songLocation(graph, songUri):
    loc = URIRef("file://%s" % songOnDisk(songUri))
    _songUris[loc] = songUri
    return loc
    
def songUri(graph, locationUri):
    return _songUris[locationUri]

class root(PrettyErrorHandler, cyclone.web.RequestHandler):
    def get(self):
        self.set_header("Content-Type", "application/xhtml+xml")
        # todo: use a template; embed the show name and the intro/post
        # times into the page
        self.write(render.index(host=socket.gethostname()))

def playerSongUri(graph, player):
    """or None"""
    
    playingLocation = player.getSong()
Exemple #9
0
from binascii import hexlify
from twisted.web.client import getPage
from twisted.internet.defer import inlineCallbacks, returnValue
from nevow import rend, static, loaders, tags as T, inevow, json, url, flat
from rdflib import URIRef, Namespace, Variable, Literal
from commandinference.dbclient import nowLiteral

from pymongo import Connection, DESCENDING
from dateutil.tz import tzlocal
from dateutil.parser import parse
from web.contrib.template import render_genshi
from cyclone.httpclient import fetch

from graphitetemp import getAllTemps

render = render_genshi(".", auto_reload=True)

import activitystream

reload(activitystream)
ActivityStream = activitystream.ActivityStream

logging.basicConfig()
log = logging.getLogger()

import stripchart

reload(stripchart)

CMD = Namespace("http://bigasterisk.com/magma/cmd/")
CL = Namespace("http://bigasterisk.com/ns/command/v1#")
Exemple #10
0
import logging, web, datetime
from dateutil.tz import tzlocal
from web.contrib.template import render_genshi
render = render_genshi('freeway/report', auto_reload=True)
import freeway
print freeway
from freeway.db import getDb
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)
logging.getLogger("monetdb").setLevel(logging.INFO)


class root(object):
    def GET(self):
        import route_history_report
        reload(route_history_report)
        #import segment_report
        #reload(segment_report)
        #table = segment_report.table(latestMeas)
        shadows = web.input().get('shadow', 'on') != 'off'

        diaNorth = route_history_report.Diagram(db,
                                                freewayDir='N',
                                                shadows=shadows)
        diaSouth = route_history_report.Diagram(db,
                                                freewayDir='S',
                                                shadows=shadows)

        dataTime = datetime.datetime.fromtimestamp(
            diaNorth.latestRow['dataTime'], tzlocal())
Exemple #11
0
import logging, web, datetime
from dateutil.tz import tzlocal
from web.contrib.template import render_genshi
render = render_genshi('freeway/report', auto_reload=True)
import freeway
print freeway
from freeway.db import getDb
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)
logging.getLogger("monetdb").setLevel(logging.INFO)


class root(object):
    def GET(self):
        import route_history_report
        reload(route_history_report)
        #import segment_report
        #reload(segment_report)
        #table = segment_report.table(latestMeas)
        shadows = web.input().get('shadow', 'on') !=  'off'

        diaNorth = route_history_report.Diagram(db, freewayDir='N', shadows=shadows)
        diaSouth = route_history_report.Diagram(db, freewayDir='S', shadows=shadows)

        dataTime = datetime.datetime.fromtimestamp(diaNorth.latestRow['dataTime'], tzlocal())
        fetchTime = datetime.datetime.fromtimestamp(diaNorth.latestRow['readTime'], tzlocal())
        now = datetime.datetime.now(tzlocal())

        ua = web.ctx.environ['HTTP_USER_AGENT']
        print ua
Exemple #12
0
from twisted.internet import reactor
from db import DbMongo

SIOC = Namespace("http://rdfs.org/sioc/ns#")
CONTENT = Namespace("http://purl.org/rss/1.0/modules/content/")
DCTERMS = Namespace("http://purl.org/dc/terms/")
XS = Namespace("http://www.w3.org/2001/XMLSchema#")
FOAF = Namespace("http://xmlns.com/foaf/0.1/")
HTTP = Namespace("http://www.w3.org/2006/http#")
OV = Namespace("http://open.vocab.org/terms/")

log = logging.getLogger()
logging.basicConfig(format='%(asctime)s:%(levelname)s:%(name)s:%(message)s')
log.setLevel(logging.INFO)

render = render_genshi(['.'], auto_reload=False)

def literalFromUnix(t):
    i = datetime.fromtimestamp(int(t)).replace(tzinfo=tzlocal()).isoformat()
    return Literal(i, datatype=XS['dateTime'])


def agoString(literalTime):
    d = parse(str(literalTime))
    # (assuming 'now' is in the same timezone as d)
    return web.utils.datestr(d, datetime.now().replace(tzinfo=tzlocal()))

def newPublicUser(forwardedFor, name, email):
    """
    a non-logged-in user is posting a comment on a resource that's
    open for public comments. We make a new URI for this user (every
Exemple #13
0
#!bin/python
import web, pymongo, random, json, datetime
from dateutil.tz import tzutc
from web.contrib.template import render_genshi
render = render_genshi(['.'], auto_reload=True)

alphabet = 'abcdefghijklmnpqrstuvwxyz123456789'
db = pymongo.Connection('localhost', 27017, tz_aware=True)['shortener']
uris = db['uris']
follows = db['follows']

class index(object):
    def GET(self):
        web.header("content-type", "application/json")
        return render.index()

def newShort():
    for tries in range(500):
        size = 3 + tries / 50
        s = ''.join(random.choice(alphabet) for i in range(size))
        if not uris.find_one({"short" : s}):
            return s
    raise ValueError("failed to find a new short URI code")

class shortLink(object):
    def GET(self):
        longUri = web.input()['long']
        # still full of races, including multiple shorts for one long
        # (ok) and multiple longs getting one short (bad)
        match = uris.find_one({"long" : longUri})
        if not match: