Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. @api.route('/currencyData')
  2. class Currency(Resource):
  3.     def get(self):
  4.         lastData = CurrencyData.query.order_by(-CurrencyData.id).first()
  5.         return lastData #json
  6.  
  7.     @api.marshal_with(CurrencyData, envelope='resource')
  8.     def put(self):
  9.         if request.form:
  10.             try:
  11.                 print(request.form)
  12.                 c = CurrencyData(eur=request.form.get("eur"), usd=request.form.get("usd"), jpy=request.form.get("jpy"), gbp=request.form.get("gbp"), dataDateTime=date.today())
  13.                 print("Pobrane dane: ", c)
  14.                 db.session.add(c)
  15.                 db.session.commit()
  16.            
  17.                 return c #pomyślna operacja
  18.             except Exception as e:
  19.                 print("Failed to add new data: ", e)
  20.                 return 500 #błąd serwera
  21.         return 400 #jakiś błąd użytkownika
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement