Пример #1
0
def import_devices():
    with open("devices.json", "r") as f:
        data = json.load(f)
        for device in data:
            d = Device.objects(model=device['model'])
            if d:
                d.update(**device)
            else:
                Device(**device).save()
    if os.path.isfile("devices_local.json"):
        with open("devices_local.json", "r") as f:
            data = json.load(f)
            for device in data:
                d = Device.objects(model=device['model'])
                if d:
                    d.update(**device)
                else:
                    Device(**device).save()
Пример #2
0
def report():
    tested_data = json.loads(request.data)
    url = generate_report(tested_data)

    ip = str(tested_data['camInfo']['ip'])
    port = str(tested_data['camInfo']['port'])

    device = Device.query.filter(Device.ip == ip, Device.port == port).first()
    if device is None:
        device = Device(ip=ip,
                        port=port,
                        type='device',
                        name='%s:%s' % (ip, port))
        db.session.add(device)

    dbreport = TestResults(device=device,
                           user=g.user,
                           url=url,
                           rawText=json.dumps(tested_data))
    db.session.add(dbreport)
    db.session.commit()

    return jsonify(response=url)