def main(): db_conn = create_sqlite3_connection() cursor = db_conn.cursor() data = energy_data.get_data() if data is not None: try: sql = "INSERT INTO energy (production, import, export, power_production, power_import, power_export, production_deye, power_production_deye) \ VALUES (?, ?, ?, ?, ?, ?, ?, ?)" cursor.execute(sql, ( data['energy_flara'], data['total_energy_import'], data['total_energy_export'], data['power_flara'], data['power_import'], data['power_export'], data['energy_deye'], data['power_deye'], )) db_conn.commit() except Error as e: print(e) cursor.close() db_conn.close()
def get_current_power_data(context): current_data = energy_data.get_data() if current_data is None: return make_response('', 500) return jsonify({ 'production': current_data['power_production'], 'consumption': current_data['power_consumption'], 'use': current_data['power_use'], 'import': current_data['power_import'], 'export': current_data['power_export'], 'store': current_data['power_store'] })
def get_power_data(context): current_data = energy_data.get_data() if current_data is None: return make_response('Urządzenia pomiarowe nie odpowiadają', 500) return make_response( jsonify({ 'production': current_data['power_production'], 'consumption': current_data['power_consumption'], 'use': current_data['power_use'], 'import': current_data['power_import'], 'export': current_data['power_export'], 'store': current_data['power_store'] }), 200)