dashboard/api/settings/channels/obd.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, Obd, ObdSchema , ObdInput, ObdInputSchema, ChannelInputSimilar blocks of code found in 2 locations. Consider refactoring. Similar blocks of code found in 2 locations. Consider refactoring.class OBDChannel(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. obd = Obd.query.all()Similar blocks of code found in 2 locations. Consider refactoring. obd_schema = ObdSchema(many=True)Similar blocks of code found in 2 locations. Consider refactoring. return {'obd': obd_schema.dump(obd)}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['obd']Similar blocks of code found in 2 locations. Consider refactoring. obd_input = ObdInput(name=params['name'], obd=Obd.query.get(params['obd_id']))Similar blocks of code found in 2 locations. Consider refactoring. channel_input = ChannelInput(obd_input=obd_input)Similar blocks of code found in 2 locations. Consider refactoring. db.session.add(obd_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}