def get(self): sensor_repo = SensorRepository() #json = request.get_json().items() #sensor_repo.set_input_json(json=json) return sensor_repo.get_all()
def put(self, id_num): sensor_repo = SensorRepository() sensor_repo.set_id(id_num) sensor = sensor_repo.get_or_404() json = request.get_json().items() sensor_repo.set_input_json(json=json) sensor_repo.set_instance(instance=sensor) return sensor_repo.modify()
def delete(self, id_num): sensor_repo = SensorRepository() sensor_repo.set_id(id_num) sensor = sensor_repo.get_or_404() sensor_repo.set_instance(sensor) return sensor_repo.delete()
def post(self): sensor_repo = SensorRepository() if request.get_json(): json = request.get_json() user_exists = get_user_existance(json["user_id"]) if user_exists: sensor_repo.set_addition_json(json=json) return sensor_repo.add() else: return "User not found", 404 return sensor_repo.add()
def get(self): sensor_repo = SensorRepository() return sensor_repo.get_all()
def get(self, id_num): sensor_repo = SensorRepository() sensor_repo.set_id(id_num) return sensor_schema.dump(sensor_repo.get_or_404())
import random import json import sqlite3 from main.repositories import SeismRepository, SensorRepository from main.extensions import scheduler, db from .functions import get_seisms_from_api, get_ids_to_delete seism_repo = SeismRepository(verified=False) sensor_repo = SensorRepository() @scheduler.task("interval", id="seisms_achiever", seconds=300) def load_seisms_task(): # We work with pandas library. First, we obtain the data, erase the unnecessary cols and then, we call the function # to load it in the database with scheduler.app.app_context(): print("\n\nTASK: Achieving seisms") seisms_data = get_seisms_from_api() # We get the available sensor ids list sensor_repo.set_db_session(session=db.session) ids_list = sensor_repo.get_sensor_id_list() for seism in seisms_data: sensor_id = int(random.choice(ids_list)) seisms_data[seism]["latitude"] = str( seisms_data[seism]["latitude"]) seisms_data[seism]["longitude"] = str( seisms_data[seism]["longitude"]) seisms_data[seism]["sensor_id"] = sensor_id