made sure that the filecache keeps is not removed when auction refresh fails
This commit is contained in:
6
app.py
6
app.py
@@ -1,11 +1,9 @@
|
||||
from utils.helperutils import log
|
||||
from traceback import print_exc
|
||||
from flask import Flask, jsonify
|
||||
from flask_cors import CORS, cross_origin
|
||||
import requests
|
||||
from flask_cors import CORS
|
||||
from cache import Cache
|
||||
from utils.auctionutils import getTwkAuctions, getAuctionlocations
|
||||
from utils.locationutils import getGeoLocationByCity
|
||||
from utils.auctionutils import getAuctionlocations
|
||||
from models.location import JsonEncoder
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
15
cache.py
15
cache.py
@@ -41,28 +41,31 @@ class CacheObj:
|
||||
|
||||
|
||||
class FileCache():
|
||||
def get(key, notOlderThanHours = 24):
|
||||
def get(key, notOlderThanHours = None):
|
||||
|
||||
filepath = "./filecache/" + key + ".json"
|
||||
cachefile = Path(filepath)
|
||||
if cachefile.is_file():
|
||||
ti_m = os.path.getmtime(filepath)
|
||||
|
||||
if(notOlderThanHours is not None):
|
||||
#checks last modified age of file, and removes it if it is too old
|
||||
log('checking time cachefile ' + filepath + ': ' + str(ti_m) + " < " + str(time.time() - (3600 * notOlderThanHours)))
|
||||
|
||||
if( ti_m < time.time() - (3600 * notOlderThanHours)):
|
||||
log('removing old filecache')
|
||||
os.remove(filepath);
|
||||
return None;
|
||||
os.remove(filepath)
|
||||
return None
|
||||
|
||||
with open(filepath) as json_file:
|
||||
json_data = json.load(json_file);
|
||||
json_data = json.load(json_file)
|
||||
log('returning json data from cachefile: ' + key)
|
||||
return json_data;
|
||||
return json_data
|
||||
|
||||
return None
|
||||
|
||||
def add(key, obj):
|
||||
log('adding filecacheobject ' + key);
|
||||
log('adding filecacheobject ' + key)
|
||||
json_data = JsonEncoder().encode(obj)
|
||||
with open("./filecache/" + key + ".json", 'w') as f:
|
||||
f.write(json_data)
|
||||
17
runapi.py
17
runapi.py
@@ -1,7 +1,16 @@
|
||||
import requests
|
||||
# import requests
|
||||
from utils.auctionutils import getAuctionlocations
|
||||
|
||||
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:
|
||||
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):
|
||||
# print('ran getauctions request successfull')
|
||||
# else:
|
||||
# print('A error occurred while running the getauctions request')
|
||||
@@ -8,10 +8,13 @@ from datetime import datetime
|
||||
import re
|
||||
import math
|
||||
|
||||
def getAuctionlocations(countrycode: Countrycode):
|
||||
def getAuctionlocations(countrycode: Countrycode, clearcache:bool = False):
|
||||
cachename = 'allauctions_' + countrycode
|
||||
|
||||
res = FileCache.get(cachename, 23)
|
||||
if(clearcache):
|
||||
res = FileCache.get(cachename, 1)
|
||||
else:
|
||||
res = FileCache.get(cachename)
|
||||
|
||||
if(res):
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user