all
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
import json
|
||||
import re
|
||||
@@ -14,41 +12,41 @@ from utils.helperutils import log
|
||||
def getAPAuctions():
|
||||
cachename = 'AuctionPort_'
|
||||
res = Cache.get(cachename)
|
||||
if(res):
|
||||
return res
|
||||
if (res):
|
||||
return res
|
||||
|
||||
try:
|
||||
response = requests.get("https://api.auctionport.be/auctions/small?size=100&page=1")
|
||||
response = requests.get("https://api.auctionport.be/auctions/small?size=100&page=1")
|
||||
except:
|
||||
log("The Auctionport auctions call threw a error")
|
||||
|
||||
if(response is None):
|
||||
return []
|
||||
|
||||
if(response.status_code ==200):
|
||||
if (response is None):
|
||||
return []
|
||||
|
||||
if (response.status_code == 200):
|
||||
log('Got AP Auctions')
|
||||
try:
|
||||
data = response.json()
|
||||
pages = data['pages']
|
||||
auctions = []
|
||||
for i in range(0,pages-1,1):
|
||||
for i in range(0, pages - 1, 1):
|
||||
log("getting page " + str(i) + ' of ' + str(pages))
|
||||
# if(i > 1):
|
||||
response = requests.get("https://api.auctionport.be/auctions/small?size=100&page=" + str(i))
|
||||
if(response is None): continue
|
||||
if(response.status_code != 200): continue
|
||||
if (response is None): continue
|
||||
if (response.status_code != 200): continue
|
||||
|
||||
data = response.json()
|
||||
|
||||
|
||||
for PAauction in data['data']:
|
||||
#makes sure that the locations array is filled with at least one location
|
||||
if PAauction['locations'] == []:
|
||||
# makes sure that the locations array is filled with at least one location
|
||||
if PAauction['locations'] == []:
|
||||
PAauction['locations'] = [PAauction['location']]
|
||||
|
||||
#makes sure that the auction is still active
|
||||
# makes sure that the auction is still active
|
||||
closingdate = datetime.fromisoformat(PAauction['closingDate'])
|
||||
if(closingdate.date() < datetime.now().date() ): continue
|
||||
if(PAauction['lotCount'] <= 0): continue
|
||||
if (closingdate.date() < datetime.now().date()): continue
|
||||
if (PAauction['lotCount'] <= 0): continue
|
||||
|
||||
multipleLocations = len(PAauction['locations']) > 1
|
||||
|
||||
@@ -57,21 +55,25 @@ def getAPAuctions():
|
||||
loc = re.sub('Nederland', '', location)
|
||||
# loc = location.split(",")
|
||||
postalcodeRegex = r'(.*?)[1-9][0-9]{3} ?(?!sa|sd|ss)[a-zA-Z]{2}'
|
||||
city = re.sub(postalcodeRegex , '', loc) #removes postalcode and everything in front of it
|
||||
city = city.strip() #removes whitespace
|
||||
city = city.strip(',') #removes trailing and leading ,
|
||||
city = city.split(',') #splits on , to overcome not matching regex
|
||||
city = city[len(city)-1]
|
||||
city = re.sub(postalcodeRegex, '', loc) # removes postalcode and everything in front of it
|
||||
city = city.strip() # removes whitespace
|
||||
city = city.strip(',') # removes trailing and leading ,
|
||||
city = city.split(',') # splits on , to overcome not matching regex
|
||||
city = city[len(city) - 1]
|
||||
city = city.strip()
|
||||
newauction = Auction(Auctionbrand.AP,city, Countrycode.NL, PAauction['title'], datetime.fromisoformat(PAauction['openDate']), datetime.fromisoformat(PAauction['closingDate']), '/auction/'+ str(PAauction['id']), PAauction['imageUrl'], PAauction['lotCount'] , None, multipleLocations)
|
||||
newauction = Auction(Auctionbrand.AP, city, Countrycode.NL, PAauction['title'],
|
||||
datetime.fromisoformat(PAauction['openDate']),
|
||||
datetime.fromisoformat(PAauction['closingDate']), 'https://www.auctionport.be/auction/' + str(PAauction['id']),
|
||||
PAauction['imageUrl'], PAauction['lotCount'], None, multipleLocations)
|
||||
|
||||
auctions.append(newauction)
|
||||
Cache.add(cachename, auctions)
|
||||
return auctions
|
||||
except Exception as e:
|
||||
log(e.__cause__ + '-- Something went wrong in the mapping of AP auctions to auctionviewer objects. The reason was: ' + response.reason + '. The response was: ' + JsonEncoder().encode(response.json()))
|
||||
print_exc(e)
|
||||
|
||||
log(e.__cause__ + '-- Something went wrong in the mapping of AP auctions to auctionviewer objects. The reason was: ' + response.reason + '. The response was: ' + JsonEncoder().encode(
|
||||
response.json()))
|
||||
print_exc(e)
|
||||
|
||||
else:
|
||||
log("The AP auctions call didn't gave a 200 response but a " + str(response.status_code) + ". With the reason: " + response.reason)
|
||||
return []
|
||||
log("The AP auctions call didn't gave a 200 response but a " + str(response.status_code) + ". With the reason: " + response.reason)
|
||||
return []
|
||||
|
||||
Reference in New Issue
Block a user