dashboard/api/settings/channels/consult.py
Similar blocks of code found in 2 locations. Consider refactoring.from flask_restful import ResourceSimilar blocks of code found in 2 locations. Consider refactoring.from flask import request, jsonifySimilar blocks of code found in 2 locations. Consider refactoring.from model.models import db, Consult, ConsultSchema , NissanInput, NissanInputSchema, ChannelInputSimilar blocks of code found in 2 locations. Consider refactoring. Similar blocks of code found in 2 locations. Consider refactoring.class ConsultChannel(Resource):Similar blocks of code found in 2 locations. Consider refactoring. Similar blocks of code found in 2 locations. Consider refactoring. def get(self):Similar blocks of code found in 2 locations. Consider refactoring. consult = Consult.query.all()Similar blocks of code found in 2 locations. Consider refactoring. consult_schema = ConsultSchema(many=True)Similar blocks of code found in 2 locations. Consider refactoring. return {'consults': consult_schema.dump(consult)}Similar blocks of code found in 2 locations. Consider refactoring. Similar blocks of code found in 2 locations. Consider refactoring. def post(self):Similar blocks of code found in 2 locations. Consider refactoring. try: Similar blocks of code found in 2 locations. Consider refactoring. params = request.json['consult']Similar blocks of code found in 2 locations. Consider refactoring. consult_input = NissanInput(name=params['name'], consult=Consult.query.get(params['consult_id']))Similar blocks of code found in 2 locations. Consider refactoring. channel_input = ChannelInput(nissan_input=consult_input)Similar blocks of code found in 2 locations. Consider refactoring. db.session.add(consult_input)Similar blocks of code found in 2 locations. Consider refactoring. db.session.add(channel_input)Similar blocks of code found in 2 locations. Consider refactoring. db.session.commit()Similar blocks of code found in 2 locations. Consider refactoring. return {'response': True}Similar blocks of code found in 2 locations. Consider refactoring. except: Similar blocks of code found in 2 locations. Consider refactoring. return {'response': False}, 500Similar blocks of code found in 2 locations. Consider refactoring. Similar blocks of code found in 2 locations. Consider refactoring. def patch(self):Similar blocks of code found in 2 locations. Consider refactoring. try:Similar blocks of code found in 2 locations. Consider refactoring. analog = request.json['analog']Similar blocks of code found in 2 locations. Consider refactoring. cursor = self.database.con.cursor()Similar blocks of code found in 2 locations. Consider refactoring. input = 1 if analog["input"] == "Voltage" else 0Similar blocks of code found in 2 locations. Consider refactoring. cursor.execute("UPDATE analog_channels SET name = ?, pin = ?, voltage_resistance = ? WHERE id = ? ", (analog["name"], analog["pin"], input, str(analog["id"])))Similar blocks of code found in 2 locations. Consider refactoring. self.database.con.commit()Similar blocks of code found in 2 locations. Consider refactoring. return {'response': True}Similar blocks of code found in 2 locations. Consider refactoring. except: Similar blocks of code found in 2 locations. Consider refactoring. return {'response': False}