From a0e87927af3b474c5034f26c370cc1e82d76bfc7 Mon Sep 17 00:00:00 2001 From: Computerboer Date: Sat, 19 Oct 2024 14:43:21 +0200 Subject: [PATCH] switched cron job to http request --- app.py | 17 +++++++++++++++++ cache.py | 2 +- runapi.py | 28 ++++++++++++++-------------- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/app.py b/app.py index 402aa6d..acf191d 100644 --- a/app.py +++ b/app.py @@ -31,6 +31,23 @@ def getAllAuctions(countrycode): print_exc(e) return 'internal server error', 500 +@app.route("/v2/refreshauction/") +def refreshAllAuctions(countrycode): + try: + if countrycode not in ['NL', 'BE', 'DE']: + log('country not available: ' + countrycode) + return jsonify('NOT AVAILABLE COUNTRY') + + res = getAuctionlocations(countrycode, True) + return JsonEncoder().encode(res) + + except Exception as e: + log('something went wrong with refreshing the auctions') + print_exc(e) + return 'internal server error' + e, 500 + + + if __name__ == "__main__": app.run() # run our Flask app diff --git a/cache.py b/cache.py index cf3b7c7..8643b08 100644 --- a/cache.py +++ b/cache.py @@ -67,5 +67,5 @@ class FileCache(): def add(key, obj): log('adding filecacheobject ' + key) json_data = JsonEncoder().encode(obj) - with open("./filecache/" + key + ".json", 'w') as f: + with open("./filecache/" + key + ".json", 'w+') as f: f.write(json_data) \ No newline at end of file diff --git a/runapi.py b/runapi.py index 7f558c4..8eb51fb 100644 --- a/runapi.py +++ b/runapi.py @@ -1,16 +1,16 @@ -# import requests -from utils.auctionutils import getAuctionlocations +import requests +# from utils.auctionutils import getAuctionlocations -try: - getAuctionlocations('NL', True) - print('ran getauctions request successfull') -except Exception as e: - print('A error occurred while running the getauctions request') - print(e) - - -# response = requests.get('https://api.auctionviewer.ikbenhenk.nl//v2/auction/NL') -# if(response.status_code ==200): +# try: +# getAuctionlocations('NL', True) # print('ran getauctions request successfull') -# else: -# print('A error occurred while running the getauctions request') \ No newline at end of file +# except Exception as e: +# print('A error occurred while running the getauctions request') +# print(e) + + +response = requests.get('https://api.auctionviewer.ikbenhenk.nl//v2/refreshauction/NL') +if(response.status_code ==200): + print('ran getauctions request successfull') +else: + print('A error occurred while running the getauctions request') \ No newline at end of file