├── install.sh ├── LICENSE └── check_camera.py /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sudo ln -s `pwd`/check_camera.py /usr/local/bin/check_camera 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Latona, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /check_camera.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import MySQLdb 3 | import simplejson as json 4 | 5 | 6 | MYSQL_HOST = "127.0.X.X" 7 | MYSQL_PORT = 30000 8 | MYSQL_USER = "latona" 9 | MYSQL_PASSWORD = "XXXXXXXX" 10 | 11 | class UpdateDeviceStateToDB(): 12 | def __init__(self): 13 | self.connection = MySQLdb.connect( 14 | host=MYSQL_HOST, 15 | port=MYSQL_PORT, 16 | user=MYSQL_USER, 17 | passwd=MYSQL_PASSWORD, 18 | db='PeripheralDevice', 19 | charset='utf8') 20 | self.cursor = self.connection.cursor(MySQLdb.cursors.DictCursor) 21 | 22 | def update_up_device_state(self): 23 | sql = """ 24 | SELECT state FROM cameras 25 | WHERE state = 1 LIMIT 1 26 | """ 27 | self.cursor.execute(sql) 28 | return self.cursor.fetchone() 29 | 30 | 31 | if __name__ == "__main__": 32 | db = UpdateDeviceStateToDB() 33 | res = db.update_up_device_state() 34 | if isinstance(res, dict): 35 | try: 36 | print(json.dumps(res)) 37 | exit(0) 38 | except Exception: 39 | pass 40 | print(json.dumps({"state": 0})) 41 | --------------------------------------------------------------------------------