Esempio n. 1
0
def index():
    dbHelper = DbAzureBlob()

    if not os.path.isfile(DATABASE_NAME):
        print("reseting")
        dbHelper.setupDatabase()

    conn = sqlite3.connect(DATABASE_NAME)

    row = conn.execute(
        "SELECT * FROM jobs WHERE processed = 0 ORDER BY RANDOM() LIMIT 1"
    ).fetchone()

    if (row == None):
        return json.dumps({
            'filename': "NULL",
            'processed': 1,
        })

    id = row[0]
    filename = row[1]
    conn.close()

    return Response(json.dumps({
        'id': id,
        'filename': filename,
        'processed': 0
    }),
                    status=200,
                    mimetype='application/json')
Esempio n. 2
0
def index():
    dbHelper = DbAzureBlob()

    if not os.path.isfile(DATABASE_NAME):
        print("reseting")
        dbHelper.setupDatabase()

    conn = sqlite3.connect(DATABASE_NAME)

    row = conn.execute(
        "SELECT * FROM jobs WHERE processed = 0 ORDER BY RANDOM() LIMIT 1"
    ).fetchone()

    if (row == None):
        current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        conn.execute("UPDATE time set finished = 1, finish_time = \"" +
                     current_time + "\" where id = 1;")
        conn.commit()

        return json.dumps({
            'filename': "NULL",
            'processed': 1,
        })

    cursor = conn.execute("SELECT * FROM time WHERE id = 1;")

    if (cursor.fetchone()[4] == 0):
        current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        conn.execute("UPDATE time set started = 1, start_time = \"" +
                     current_time + "\" where id = 1;")
        conn.commit()

    id = row[0]
    filename = row[1]

    conn.execute("UPDATE jobs set processed = 1 where id = " + str(id) + ";")
    conn.commit()

    conn.close()

    return Response(json.dumps({
        'filename': filename,
        'processed': 0
    }),
                    status=200,
                    mimetype='application/json')