| @@ 518-540 (lines=23) @@ | ||
| 515 | cursor.execute(query, (id_,)) |
|
| 516 | row = cursor.fetchone() |
|
| 517 | ||
| 518 | if row is None: |
|
| 519 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 520 | description='API.SENSOR_NOT_FOUND') |
|
| 521 | else: |
|
| 522 | meta_result = {"id": row[0], |
|
| 523 | "name": row[1], |
|
| 524 | "uuid": row[2], |
|
| 525 | "description": row[3], |
|
| 526 | "points": None} |
|
| 527 | query = (" SELECT p.id, p.name " |
|
| 528 | " FROM tbl_points p, tbl_sensors_points sp " |
|
| 529 | " WHERE sp.sensor_id = %s AND p.id = sp.point_id " |
|
| 530 | " ORDER BY p.id ") |
|
| 531 | cursor.execute(query, (id_,)) |
|
| 532 | rows = cursor.fetchall() |
|
| 533 | result = list() |
|
| 534 | if rows is not None and len(rows) > 0: |
|
| 535 | for row in rows: |
|
| 536 | point_result = {"id": row[0], "name": row[1]} |
|
| 537 | result.append(point_result) |
|
| 538 | meta_result['points'] = result |
|
| 539 | cursor.close() |
|
| 540 | cnx.close() |
|
| 541 | resp.text = json.dumps(meta_result) |
|
| 542 | ||
| 543 | ||
| @@ 658-681 (lines=24) @@ | ||
| 655 | " WHERE id = %s ") |
|
| 656 | cursor.execute(query, (id_,)) |
|
| 657 | row = cursor.fetchone() |
|
| 658 | if row is None: |
|
| 659 | cursor.close() |
|
| 660 | cnx.close() |
|
| 661 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 662 | description='API.SENSOR_NOT_FOUND') |
|
| 663 | else: |
|
| 664 | meta_result = {"id": row[0], |
|
| 665 | "name": row[1], |
|
| 666 | "uuid": row[2], |
|
| 667 | "description": row[3], |
|
| 668 | "points": None} |
|
| 669 | ||
| 670 | query = (" SELECT p.id, p.name " |
|
| 671 | " FROM tbl_points p, tbl_sensors_points sp " |
|
| 672 | " WHERE sp.sensor_id = %s AND p.id = sp.point_id " |
|
| 673 | " ORDER BY p.id ") |
|
| 674 | cursor.execute(query, (id_,)) |
|
| 675 | rows = cursor.fetchall() |
|
| 676 | result = list() |
|
| 677 | if rows is not None and len(rows) > 0: |
|
| 678 | for row in rows: |
|
| 679 | point_result = {"id": row[0], "name": row[1]} |
|
| 680 | result.append(point_result) |
|
| 681 | meta_result['points'] = result |
|
| 682 | timezone_offset = int(config.utc_offset[1:3]) * 60 + int(config.utc_offset[4:6]) |
|
| 683 | if config.utc_offset[0] == '-': |
|
| 684 | timezone_offset = -timezone_offset |
|