Exemplo n.º 1
0
class PlantInternal:
    def __init__(self):
        self._fetcher = SQLiteDataFetcher('db')

    def get_plants_list(self):
        statement = """SELECT * FROM plants"""
        data = self._fetcher.fetch_data(statement, ())
        return jsonify(data)

    def get_plant_info(self, plant_id):
        statement = """SELECT * FROM plants WHERE plant_id = ?"""
        parameters = (str(plant_id))
        data = self._fetcher.fetch_data(statement, parameters)
        if data == None:
            flask_restful.abort(
                404, message='Plant not found. Maybe you should plant it?')
        else:
            return jsonify(data)

    def search_for_plant(self, search_string):
        statement = """SELECT * FROM plants WHERE name LIKE ?"""
        parameters = ('%' + str(search_string) + '%', )
        data = self._fetcher.fetch_data(statement, parameters)
        if data == None:
            flask_restful.abort(
                404, message='Plant not found. Maybe you should plant it?')
        else:
            return jsonify(data)

    def get_summarized_plants_list(self):
        statement = """SELECT plant_id, name, category, time_planting FROM plants"""
        data = self._fetcher.fetch_data(statement, ())
        return jsonify(data)
Exemplo n.º 2
0
 def search_for_crop(self, search_string):
     statement = """SELECT * FROM crops WHERE name LIKE ?"""
     parameters = ('%' + str(search_string) + '%', )
     fetcher = SQLiteDataFetcher('db')
     data = fetcher.fetch_data(statement, parameters)
     if data == None:
         return flask_restful.abort(404, message='Crop not found')
     else:
         return jsonify(data)
Exemplo n.º 3
0
 def _get_plant_data(self, plant_id):
     fetcher = SQLiteDataFetcher('db')
     statement = """SELECT image_url, name, category, maturity_integer FROM plants WHERE plant_id = ?"""
     parameters = (plant_id)
     data = fetcher.fetch_data(statement, parameters)
     if data == None:
         return None
     else:
         return jsonify(data)
Exemplo n.º 4
0
class DiseasesInternal:
    def __init__(self):
        self._fetcher = SQLiteDataFetcher('db')

    def get_symptoms(self, plant_id):
        statement = """SELECT DISTINCT symptom FROM diseases WHERE plant_id = ?"""
        parameters = (str(plant_id))
        data = self._fetcher.fetch_data(statement, parameters)
        return jsonify(data)

    def get_disease(self, symptoms, plant_id):
        file_name = 'datasets' + '/' + plant_id + '.py'
        output = subprocess.run(['python2', file_name, symptoms],
                                stdout=subprocess.PIPE).stdout
        json_string = json.loads(output.decode('utf8'))
        return jsonify(json_string)
Exemplo n.º 5
0
 def __init__(self):
     self._fetcher = SQLiteDataFetcher('db')
 def _get_tasks(self, day, plant_id):
     fetcher = SQLiteDataFetcher('db')
     statement = """SELECT time, description, time_frame FROM tasks WHERE plant_id = ? AND day = ?"""
     parameters = (plant_id, day)
     task_data = jsonify(fetcher.fetch_data(statement, parameters))
     return json.loads(task_data.get_data().decode("utf-8"))
Exemplo n.º 7
0
 def get_crops(self):
     statement = """SELECT * FROM crops"""
     fetcher = SQLiteDataFetcher('db')
     data = fetcher.fetch_data(statement, ())
     return jsonify(data)
Exemplo n.º 8
0
 def _get_crop_data_json(self, crop_id):
     fetcher = SQLiteDataFetcher('db')
     statement = """SELECT plant_id, name, plant_date FROM crops WHERE crop_id = ?"""
     parameters = (crop_id)
     crop_data = jsonify(fetcher.fetch_data(statement, parameters))
     return json.loads(crop_data.get_data().decode("utf-8"))[0]