The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Asd
By Guest on 15th May 2019 09:50:26 AM | Syntax: TEXT | Views: 4



New paste | Download | Show/Hide line no. | Copy text to clipboard
  1. import os
  2.  
  3. from flask import Flask, request
  4. from flask_restful import Resource, Api
  5.  
  6. from Database.UserRepository import getAllUsers
  7.  
  8. app = Flask(__name__)
  9. api = Api(app)
  10.  
  11. UPLOAD_FOLDER = os.path.basename('')
  12. app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
  13. class Employees(Resource):
  14.     def get(self):
  15.         return {'employees': 25}  # Fetches first column that is Employee ID
  16.  
  17.     def post(self, data):
  18.         return {'cevap': True},201
  19.  
  20.     def put(self,data):
  21.         print (data)
  22.         return {'cevap': 'bacin'},201
  23.     def delete(self):
  24.         pass
  25.  
  26.  
  27. class Tracks(Resource):
  28.     def get(self):
  29.         return {'login': True}
  30.  
  31.  
  32. class Employees_Name(Resource):
  33.     def get(self, employee_id):
  34.         return {'employee_id': int(employee_id) * 100}
  35.  
  36.  
  37. api.add_resource(Employees, '/employees')  # Route_1
  38. api.add_resource(Tracks, '/tracks')  # Route_2
  39. api.add_resource(Employees_Name, '/employees/<employee_id>')  # Route_3
  40. @app.route('/users/<user_id>', methods = ['GET', 'POST', 'DELETE'])
  41. def user(user_id):
  42.     if request.method == 'GET':
  43.         print ("get")
  44.         msg = getAllUsers()
  45.         return "success for user id {} with msg {}".format(user_id, msg)
  46.     if request.method == 'POST':
  47.         print ("post")
  48.         print(request.form.get('annen'))
  49.         file = request.files['media']
  50.         return "success"
  51.     if request.method == 'DELETE':
  52.         print ("delete")
  53.         return "success"
  54.     else:
  55.         # POST Error 405 Method Not Allowed
  56.         return "success"
  57.  
  58. def abort(ERROR_CODE):
  59.     print("Error code: {}".format(ERROR_CODE))
  60.  
  61. @app.before_request
  62. def limit_remote_addr():
  63.     print("Request coming from IP : {}".format(request.remote_addr ))
  64.     if request.remote_addr != '10.20.30.40': # define Allowed ips here
  65.         abort(403)  # Forbidden
  66.  
  67. from flask import jsonify
  68. # @app.route('/otpfinder', methods = ['POST'])
  69. # def otpfinder():
  70. #     if request.method == 'POST':
  71. #         for j in range(0, 10):
  72. #             takenNumberImage = "n{}".format(j)
  73. #             file = request.files[takenNumberImage]
  74. #             f = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
  75. #             # add your custom code to check that the uploaded file is a valid image and not a malicious file (out-of-scope for this post)
  76. #             file.save(f)
  77. #
  78. #         numbersOfOTP = []
  79. #         for i in range(0, 10):
  80. #             currentNumberImage = "num{}.png".format(i)
  81. #             currentNumberImage = cv2.imread(currentNumberImage)
  82. #             currentNumberImage = cv2.cvtColor(currentNumberImage, cv2.COLOR_BGR2GRAY)
  83. #
  84. #             imageSimilarity = -1
  85. #             for j in range(0, 10):
  86. #                 takenNumberImage = "n{}.png".format(j)
  87. #                 imgName = takenNumberImage
  88. #                 takenNumberImage = cv2.imread(takenNumberImage)
  89. #                 takenNumberImage = cv2.cvtColor(takenNumberImage, cv2.COLOR_BGR2GRAY)
  90. #                 imageSimilarity = 1
  91. #                 if imageSimilarity == 1:
  92. #                     print("Number {} corresponds to taken image of {}".format(i, imgName))
  93. #                     numbersOfOTP.append(j)
  94. #         return jsonify({'numbersOfOTP': numbersOfOTP}), 200
  95. if __name__ == '__main__':
  96.     app.run(host='0.0.0.0',port='5002')



  • Recent Pastes
  • Fdsfd
    41 mins 58 secs ago
  • Sdfsdf s
    42 mins 54 secs ago
  • Surung
    58 mins 34 secs ago
  • Cozy
    1 hour 59 secs ago
  • V4a
    1 hour 8 mins 6 secs ago