Added serverside modeling

This commit is contained in:
Computerboer
2023-06-16 00:53:23 +02:00
parent 53b7d14b9e
commit 78afe97442
9 changed files with 23197 additions and 21 deletions

31
app.py
View File

@@ -1,7 +1,12 @@
from traceback import print_exc
from flask import Flask, jsonify
from flask_cors import CORS, cross_origin
import requests
from config import Cache
from cache import Cache
from utils.auctionutils import getTwkAuctions, getAuctionlocations
from utils.locationutils import getGeoLocationByCity
from models.location import JsonEncoder
import json
app = Flask(__name__)
CORS(app, resources={r"/auction/*": {"origins": ["http://localhost:4200","https://auctionviewer.ikbenhenk.nl", "https://victorious-bay-0d278c903.3.azurestaticapps.net"]}})
@@ -14,22 +19,20 @@ def gethome():
@app.route("/auction/<countrycode>")
def get(countrycode):
try:
if countrycode not in ['NL', 'BE', 'DE']:
print(f'country not available: {countrycode} ')
return jsonify('NOT AVAILABLE COUNTRY')
if countrycode not in ['NL', 'BE', 'DE']:
print(f'country not available: {countrycode} ')
return jsonify('NOT AVAILABLE COUNTRY')
res = Cache.get(countrycode)
if(res):
return res.obj
res = getAuctionlocations(countrycode)
#return json.dumps(res, sort_keys=True, default=str)
return JsonEncoder().encode(res)
response = requests.get("https://api.troostwijkauctions.com/sale/4/listgrouped?batchSize=99999&CountryIDs=" + countrycode)
print(f'request statuscode: {response.status_code} ')
if(response.status_code ==200):
Cache.add(countrycode, response.json())
return response.json();
except Exception as e:
print('something went wrong ')
print_exc(e)
return 'internal server error', 500
if __name__ == "__main__":
app.run() # run our Flask app