-1
from prettytable import PrettyTable
from flask import Flask, request
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
class Structure_Cal:
    def __init__(self, Slope, Texture,Soil_depth,Catchment_area,Land_use):
        self.slope=Slope
        self.texture=Texture
        self.soil_depth=Soil_depth
        self.catchment_area=Catchment_area
        self.land_use=Land_use
    def sturcture_defined(self, index):
        stucture_def=['Field bunding with waste weir','Outlet structure (grassed turfing or stone pitching)',
                      'Masonry mini drop (outlet)','On Farm lined pond (small)','On Farm unlined pond (small)',
                      'Farm pond (big) IFS' ,'Staggered trench','Field boundary trench-cum-bund','Staggered trench',
                      'Diversion drain with WHS','contour stone bunding','recharge pit','contour stone bunding',
                      'Vegetative and live check dams','loose boulder check dams','earthern check dams with surplus weir',
                      'Gabion structure','Percolation tanks with dug well ','Stream bank protection measures','WHS',
                      'MasonryCheck dam/drop inlet structure','Stream bank protection measures' ]
        return stucture_def[index]
    def strcuture_calculation(self):
        """ This is the function that 
        calcualte the Strcture with the value
        of slope, soil_depth, catchment_area,
        land_use user values
        """
        ### For the first one ####
        if (int(self.slope) in range(3, 6) and self.texture=='Any soil' 
               and int(self.soil_depth) in range(50,101) and self.catchment_area ==0 and self.land_use=='Arable Upland'):
            idf=0
            fin_struct=self.sturcture_defined(idf)
        elif (int(self.slope) in range(1, 4) and self.texture=='Any soil' 
               and int(self.soil_depth) in range(1,101) and self.catchment_area ==1 and self.land_use=='Arable Medium land'):
            idf=1
            fin_struct=self.sturcture_defined(idf)
        return fin_struct
###### Testing ###########
if __name__ == '__main__':
    

    
    if request.method == "POST":
        Slope = request.form["ENTER THE VALUE"]
    Texture=input('Enter Texture Value:')
    Soil_depth=int(input('Enter Slope-Depth Value:'))
    Catchment_area=int(input('Enter Catchment-area Value:'))
    Land_use=input('Enter Land-use Value:')
    ########
    Struture=Structure_Cal(Slope,Texture,Soil_depth,Catchment_area,Land_use)
    F_Structure=Struture.strcuture_calculation()
    ########  Output #########
    data_output=PrettyTable(['Slope','Texture','Soil_depth','Catchment_area','Land_use','Structure_Output'])
    data_output.add_row([Slope,Texture,Soil_depth,Catchment_area,Land_use,F_Structure])
    ### Output to Excel
    with open('structure_output_final.csv', 'w', newline='') as f_output:
        f_output.write(data_output.get_csv_string())
    
    app.run()
    ####
    print(data_output)

My code, is showing internal server error, why?

James Z
  • 12,209
  • 10
  • 24
  • 44
  • Next time, look at the question before you post it. It was a complete unreadable mess. Also, please don't ever write anything IN ALL CAPS. – James Z Feb 02 '23 at 06:35

1 Answers1

0

I noticed a few issues with your code.

First of all you can't decorate a class with @app.route("/", methods=["GET", "POST"]). Instead you could create a class based view. If that's what you want to do you could take a look at the documentation: https://flask.palletsprojects.com/en/2.2.x/views/

Also in the codesample you provided, there is a lot of code inside the if __name__ = __main__: that can't be there without raising a RuntimeError. So better double check your question to see if everything is in its proper place.

Cpt_Freeze
  • 71
  • 5