diff --git a/Auctionviewer.api.pyproj b/Auctionviewer.api.pyproj index b704dc8..e03b9ea 100644 --- a/Auctionviewer.api.pyproj +++ b/Auctionviewer.api.pyproj @@ -31,7 +31,6 @@ - diff --git a/app.py b/app.py index 21de44c..09cc89b 100644 --- a/app.py +++ b/app.py @@ -6,10 +6,9 @@ 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"]}}) +CORS(app, resources={r"/*": {"origins": ["http://localhost:4200","https://auctionviewer.ikbenhenk.nl", "https://victorious-bay-0d278c903.3.azurestaticapps.net"]}}) application = app # our hosting requires application in passenger_wsgi @app.route("/") @@ -17,7 +16,7 @@ def gethome(): return "application is working!" @app.route("/v2/auction/") -def get(countrycode): +def getAllAuctions(countrycode): try: if countrycode not in ['NL', 'BE', 'DE']: print(f'country not available: {countrycode} ') @@ -34,17 +33,24 @@ def get(countrycode): return 'internal server error', 500 -@app.route("/v1/auction/") -def get(countrycode): +@app.route("/auction/") +def getTwkAuctions(countrycode): try: 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 ') diff --git a/models/auction.py b/models/auction.py deleted file mode 100644 index e69de29..0000000 diff --git a/models/location.py b/models/location.py index 146aa65..50ddeda 100644 --- a/models/location.py +++ b/models/location.py @@ -1,7 +1,4 @@ from enum import Enum -import numbers -import string -import json from json import JSONEncoder class Countrycode(Enum): diff --git a/requirements.txt b/requirements.txt index 9093037..4340267 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ pip==9.0.1 setuptools==28.8.0 flask===2.0.3 flask_cors===3.0.10 -requests===2.27.1 \ No newline at end of file +requests===2.27.1 +pathlib===1.0.1 \ No newline at end of file