Fixed troostwijk new api issues
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
|
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="runapi.py" />
|
||||||
<Compile Include="app.py" />
|
<Compile Include="app.py" />
|
||||||
<Compile Include="utils\auctionutils.py" />
|
<Compile Include="utils\auctionutils.py" />
|
||||||
<Compile Include="cache.py" />
|
<Compile Include="cache.py" />
|
||||||
|
|||||||
25
app.py
25
app.py
@@ -32,31 +32,6 @@ def getAllAuctions(countrycode):
|
|||||||
print_exc(e)
|
print_exc(e)
|
||||||
return 'internal server error', 500
|
return 'internal server error', 500
|
||||||
|
|
||||||
|
|
||||||
@app.route("/auction/<countrycode>")
|
|
||||||
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
|
|
||||||
|
|
||||||
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__":
|
if __name__ == "__main__":
|
||||||
app.run() # run our Flask app
|
app.run() # run our Flask app
|
||||||
|
|
||||||
|
|||||||
5
runapi.py
Normal file
5
runapi.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
from app import getAllAuctions
|
||||||
|
from models.location import Countrycode
|
||||||
|
|
||||||
|
|
||||||
|
result = getAllAuctions('NL');
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
|
from distutils.command import build
|
||||||
import requests
|
import requests
|
||||||
from cache import Cache
|
from cache import Cache
|
||||||
from models.location import Auction, Auctionbrand, Countrycode, Maplocation
|
from models.location import Auction, Auctionbrand, Countrycode, Maplocation
|
||||||
from utils.locationutils import getGeoLocationByCity
|
from utils.locationutils import getGeoLocationByCity
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import re
|
||||||
|
import math
|
||||||
|
|
||||||
def getAuctionlocations(countrycode: Countrycode):
|
def getAuctionlocations(countrycode: Countrycode):
|
||||||
cachename = 'allauctions_' + countrycode
|
cachename = 'allauctions_' + countrycode
|
||||||
@@ -47,6 +50,20 @@ def get_geonameid(auction):
|
|||||||
return auction.geonamelocation.geonameid
|
return auction.geonamelocation.geonameid
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
# global twkDataUrl; # = ''; # 'https://www.troostwijkauctions.com/_next/data/' #e6-N0pLHv12LVGS0oYzx6/nl/'
|
||||||
|
|
||||||
|
|
||||||
|
def getTWKUrl():
|
||||||
|
response = requests.get('https://www.troostwijkauctions.com/')
|
||||||
|
if(response.status_code ==200):
|
||||||
|
buildid = re.search(r'"buildId":"([^"]*)', response.text, re.MULTILINE )
|
||||||
|
twkDataUrl = 'https://www.troostwijkauctions.com/_next/data/' + str(buildid[1]) + '/nl/'
|
||||||
|
print('buildid: ' + str(buildid[1]))
|
||||||
|
print('twkDataUrl: ' + twkDataUrl)
|
||||||
|
return twkDataUrl
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def getTwkAuctions(countrycode):
|
def getTwkAuctions(countrycode):
|
||||||
cachename = 'TwkAuctions_'+ countrycode
|
cachename = 'TwkAuctions_'+ countrycode
|
||||||
@@ -54,19 +71,55 @@ def getTwkAuctions(countrycode):
|
|||||||
if(res):
|
if(res):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
response = requests.get("https://api.troostwijkauctions.com/sale/4/listgrouped?batchSize=99999&CountryIDs=" + countrycode)
|
# buildidresponse = requests.get('https://www.troostwijkauctions.com/')
|
||||||
|
twkDataUrl = getTWKUrl();
|
||||||
|
|
||||||
|
if(twkDataUrl is None):
|
||||||
|
return [];
|
||||||
|
|
||||||
|
response = requests.get(twkDataUrl + "auctions.json?countries=" + countrycode)
|
||||||
|
|
||||||
if(response.status_code ==200):
|
if(response.status_code ==200):
|
||||||
print('Got Twk Auctions')
|
print('Got Twk Auctions')
|
||||||
data = response.json();
|
data = response.json();
|
||||||
auctions = []
|
auctions = [];
|
||||||
for result in data['results']:
|
|
||||||
for twka in result['items']:
|
totalAuctionCount = data['pageProps']['auctionList']['totalSize'];
|
||||||
a = Auction(Auctionbrand.TWK, twka['c'], twka['cc'], twka['n'], datetime.fromtimestamp(twka['sd']), datetime.fromtimestamp(twka['cd']), twka['url'], twka['ii'], twka['nol'] )
|
pages = math.ceil(totalAuctionCount / len(data['pageProps']['auctionList']['results']))
|
||||||
auctions.append(a)
|
# for result in data['pageProps']['auctionList']:
|
||||||
|
|
||||||
|
for i in range(1,pages,1):
|
||||||
|
print("getting page " + str(i) + ' of ' + str(pages))
|
||||||
|
if(i > 1):
|
||||||
|
response = requests.get(twkDataUrl + "auctions.json?countries=" + countrycode + "&page=" + str(i));
|
||||||
|
data = response.json();
|
||||||
|
|
||||||
|
for twka in data['pageProps']['auctionList']['results']:
|
||||||
|
# print(twka['urlSlug'])
|
||||||
|
auction = getTWKAuction(twkDataUrl, twka['urlSlug'])
|
||||||
|
if(auction):
|
||||||
|
auctions.append(auction)
|
||||||
Cache.add(cachename, auctions)
|
Cache.add(cachename, auctions)
|
||||||
|
|
||||||
return auctions
|
return auctions
|
||||||
|
return []
|
||||||
|
|
||||||
|
def getTWKAuction(twkDataUrl, auctionurlslug):
|
||||||
|
response = requests.get(twkDataUrl + "a/" + auctionurlslug + '.json')
|
||||||
|
if(response.status_code ==200):
|
||||||
|
data = response.json();
|
||||||
|
if(len(data['pageProps']['lots']['results']) ==0):
|
||||||
|
return None;
|
||||||
|
|
||||||
|
twka = data['pageProps']['auction'];
|
||||||
|
firstlot = data['pageProps']['lots']['results'][0]
|
||||||
|
city = "Nederland" if firstlot['location']['city'].lower() == 'online' else firstlot['location']['city']
|
||||||
|
# if(firstlot['location']['city'].lower() != 'online'):
|
||||||
|
# city = firstlot['location']['city'];
|
||||||
|
a = Auction(Auctionbrand.TWK, city, firstlot['location']['countryCode'].upper(), twka['name'], datetime.fromtimestamp(twka['startDate']), datetime.fromtimestamp(twka['minEndDate']), '/a/' + auctionurlslug, twka['image']['url'], twka['lotCount'] )
|
||||||
|
# print(a);
|
||||||
|
return a;
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def getOVMAuctions():
|
def getOVMAuctions():
|
||||||
|
|||||||
Reference in New Issue
Block a user