@@ 20-51 (lines=32) @@ | ||
17 | _ = req |
|
18 | resp.status = falcon.HTTP_200 |
|
19 | ||
20 | @staticmethod |
|
21 | def on_get(req, resp): |
|
22 | if 'API-KEY' not in req.headers or \ |
|
23 | not isinstance(req.headers['API-KEY'], str) or \ |
|
24 | len(str.strip(req.headers['API-KEY'])) == 0: |
|
25 | access_control(req) |
|
26 | else: |
|
27 | api_key_control(req) |
|
28 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
29 | cursor = cnx.cursor() |
|
30 | ||
31 | query = (" SELECT id, name, uuid, " |
|
32 | " email, phone, description " |
|
33 | " FROM tbl_contacts " |
|
34 | " ORDER BY name ") |
|
35 | cursor.execute(query) |
|
36 | rows = cursor.fetchall() |
|
37 | cursor.close() |
|
38 | cnx.close() |
|
39 | ||
40 | result = list() |
|
41 | if rows is not None and len(rows) > 0: |
|
42 | for row in rows: |
|
43 | meta_result = {"id": row[0], |
|
44 | "name": row[1], |
|
45 | "uuid": row[2], |
|
46 | "email": row[3], |
|
47 | "phone": row[4], |
|
48 | "description": row[5]} |
|
49 | result.append(meta_result) |
|
50 | ||
51 | resp.text = json.dumps(result) |
|
52 | ||
53 | @staticmethod |
|
54 | @user_logger |
@@ 19-45 (lines=27) @@ | ||
16 | _ = req |
|
17 | resp.status = falcon.HTTP_200 |
|
18 | ||
19 | @staticmethod |
|
20 | def on_get(req, resp): |
|
21 | if 'API-KEY' not in req.headers or \ |
|
22 | not isinstance(req.headers['API-KEY'], str) or \ |
|
23 | len(str.strip(req.headers['API-KEY'])) == 0: |
|
24 | access_control(req) |
|
25 | else: |
|
26 | api_key_control(req) |
|
27 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
28 | cursor = cnx.cursor() |
|
29 | ||
30 | query = (" SELECT id, name, uuid, unit_of_measure, kgce, kgco2e " |
|
31 | " FROM tbl_energy_categories " |
|
32 | " ORDER BY id ") |
|
33 | cursor.execute(query) |
|
34 | rows = cursor.fetchall() |
|
35 | cursor.close() |
|
36 | cnx.close() |
|
37 | ||
38 | result = list() |
|
39 | if rows is not None and len(rows) > 0: |
|
40 | for row in rows: |
|
41 | meta_result = {"id": row[0], "name": row[1], "uuid": row[2], "unit_of_measure": row[3], |
|
42 | "kgce": row[4], "kgco2e": row[5]} |
|
43 | result.append(meta_result) |
|
44 | ||
45 | resp.text = json.dumps(result) |
|
46 | ||
47 | @staticmethod |
|
48 | @user_logger |
@@ 23-55 (lines=33) @@ | ||
20 | _ = req |
|
21 | resp.status = falcon.HTTP_200 |
|
22 | ||
23 | @staticmethod |
|
24 | def on_get(req, resp): |
|
25 | if 'API-KEY' not in req.headers or \ |
|
26 | not isinstance(req.headers['API-KEY'], str) or \ |
|
27 | len(str.strip(req.headers['API-KEY'])) == 0: |
|
28 | access_control(req) |
|
29 | else: |
|
30 | api_key_control(req) |
|
31 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
32 | cursor = cnx.cursor() |
|
33 | ||
34 | query = (" SELECT id, name, uuid, " |
|
35 | " topic, payload, set_value, description " |
|
36 | " FROM tbl_commands " |
|
37 | " ORDER BY id ") |
|
38 | cursor.execute(query) |
|
39 | rows = cursor.fetchall() |
|
40 | cursor.close() |
|
41 | cnx.close() |
|
42 | ||
43 | result = list() |
|
44 | if rows is not None and len(rows) > 0: |
|
45 | for row in rows: |
|
46 | meta_result = {"id": row[0], |
|
47 | "name": row[1], |
|
48 | "uuid": row[2], |
|
49 | "topic": row[3], |
|
50 | "payload": row[4], |
|
51 | "set_value": row[5], |
|
52 | "description": row[6]} |
|
53 | result.append(meta_result) |
|
54 | ||
55 | resp.text = json.dumps(result) |
|
56 | ||
57 | @staticmethod |
|
58 | @user_logger |