Пример #1
0
def insert_user(skylines_key, ogn_address, add_device=False):
    """
    Arguments:
    skylines_key -- hexadecimal string (4 bytes)
    ogn_address  -- hexadecimal string (3 bytes)
    add_device   -- boolean

    raises:
    NoResultFound
    IntegrityError
    """

    validate_skylines_key(skylines_key)
    validate_ogn_address(ogn_address)

    try:
        session.query(Device).filter(Device.ogn_address == ogn_address).one()
    except NoResultFound as e:
        if not add_device:
            raise e
        else:
            device = Device(ogn_address=ogn_address)
            session.add(device)

    user = User(ogn_address=ogn_address, skylines_key=int(skylines_key, 16))
    try:
        session.add(user)
        session.commit()
    except IntegrityError as e:
        raise e
    return user.as_dict()
Пример #2
0
def import_ddb():
    """Import registered devices from the DDB (discards all devices before import)."""
    session.query(Device).delete()

    print("Import registered devices fom the DDB...")
    for device in get_ddb():
        if device['identified'] and device['tracked']:
            session.add(Device(ogn_address=device['device_id']))

    session.commit()
    print("Imported {} devices.".format(session.query(Device).count()))