Example #1
0
def get_pi_info(uid):
    tags = []
    row = DBSession.query(RasPi).filter(RasPi.uuid == uid).first()
    if row is None:
        row = RasPi()
        row.uuid = uid
        row.url = "http://www.stackexchange.com"
        row.landscape = True
        row.lastseen = datetime.now()
        row.description = ""
        row.orientation = 0
        row.browser = True
        DBSession.add(row)
        DBSession.flush()
    else:
        try:
            tagset = DBSession.query(Tags).filter(Tags.uuid == uid).all()
            for tag in tagset:
                tags.append(tag.tag)
        except Exception:
            pass

    rowdict = row.get_dict()
    rowdict['tags'] = tags
    return rowdict
Example #2
0
def main(argv=sys.argv):
    if len(argv) < 2:
        usage(argv)
    config_uri = argv[1]
    options = parse_vars(argv[2:])
    setup_logging(config_uri)
    settings = get_appsettings(config_uri, options=options)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)
    with transaction.manager:
        model = RasPi()
        model.uuid = '11:22:33:44:55:66'
        model.description = "Testing Pi"
        model.url = "http://www.facebook.com"
        model.orientation = 0
        model.browser = True
        model.lastseen = datetime.now()
        DBSession.add(model)

        tag = Tags()
        tag.uuid = '11:22:33:44:55:66'
        tag.tag = 'test'
        DBSession.add(tag)

        User = UserModel()
        User.email = '*****@*****.**'
        User.AccessLevel = 2
        DBSession.add(User)

    DBSession.flush()
Example #3
0
def view_api_ping_v2(request):
    uid = request.matchdict['uid']
    ip = request.matchdict['ip']

    now = datetime.now()

    row = DBSession.query(RasPi).filter(RasPi.uuid == uid).first()
    if row is None:
        row = RasPi()
        row.uuid = uid
        row.url = "http://www.stackexchange.com"
        row.landscape = True
        row.orientation = 0
        row.description = ""
        row.browser = True

    row.lastseen = now
    row.ip = ip
    DBSession.add(row)
    DBSession.flush()
Example #4
0
def redirect_me(request):
    uid = request.matchdict['uid']
    url = "http://www.stackexchange.com"
    try:
        row = DBSession.query(RasPi).filter(RasPi.uuid == uid).first()
        if row:
            url = row.url
            logging.info("UID {uid}: {page}".format(uid=row.uuid, page=url))
        else:
            row = RasPi()
            row.uuid = uid
            row.url = "http://www.stackexchange.com"
            row.landscape = True
            row.browser = True
            DBSession.add(row)
            DBSession.flush()
            logging.warn(
                "UID {uid} NOT FOUND. ADDED TO TABLE WITH DEFAULT URL".format(
                    uid=uid))
            url = row.url
    except Exception:
        logging.error(
            "Something went south with DB when searching for {uid}".format(
                uid=uid))

    raise exc.HTTPFound(url)
Example #5
0
 def setUp(self):
     self.config = testing.setUp()
     from sqlalchemy import create_engine
     engine = create_engine('sqlite://')
     from pi_director.models.models import (
         Base,
         RasPi,
     )
     DBSession.configure(bind=engine)
     Base.metadata.create_all(engine)
     with transaction.manager:
         model = RasPi(name='one', value=55)
         DBSession.add(model)
Example #6
0
def view_json_set_pi(request):
    # TODO: move into controller(s)
    uid = request.matchdict['uid']
    response = request.json_body

    row = DBSession.query(RasPi).filter(RasPi.uuid == uid).first()
    if row is None:
        row = RasPi()
        row.uuid = uid
    row.url = response['url']
    row.description = response['description']
    row.orientation = response['orientation']
    row.browser = response['browser']
    DBSession.add(row)
    DBSession.flush()
    rowdict = {
        'uuid': row.uuid,
        'url': row.url,
        'description': row.description,
        'orientation': row.orientation,
        'browser': row.browser
    }
    return rowdict