-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhardware.py
More file actions
36 lines (27 loc) · 773 Bytes
/
hardware.py
File metadata and controls
36 lines (27 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from flask import Flask, request, jsonify
import sqlite3 as sql
import time
import random
application = Flask(__name__)
def slow_process_to_calculate_availability(provider, name):
time.sleep(5)
return random.choice(['HIGH', 'MEDIUM', 'LOW'])
@application.route('/hardware/')
def hardware():
con = sql.connect('database.db')
c = con.cursor()
statuses = [
{
'provider': row[1],
'name': row[2],
'availability': slow_process_to_calculate_availability(
row[1],
row[2]
),
}
for row in c.execute('SELECT * from hardware')
]
con.close()
return jsonify(statuses)
if __name__ == "__main__":
application.run(host='0.0.0.0', port=5001)