display progress via tqdm
This commit is contained in:
parent
0971615f98
commit
a0971823b5
22
compare.py
22
compare.py
|
@ -11,6 +11,7 @@ from datetime import datetime
|
||||||
from tinydb import TinyDB, Query
|
from tinydb import TinyDB, Query
|
||||||
import urllib3
|
import urllib3
|
||||||
import sys
|
import sys
|
||||||
|
from tqdm import tqdm
|
||||||
import scrape_listing as sl
|
import scrape_listing as sl
|
||||||
import search_eBay as se
|
import search_eBay as se
|
||||||
import export_html as exhtml
|
import export_html as exhtml
|
||||||
|
@ -22,22 +23,21 @@ if __name__ == "__main__":
|
||||||
if database_lenght == 0:
|
if database_lenght == 0:
|
||||||
print("Unable to load seller shop database!")
|
print("Unable to load seller shop database!")
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
print("Loaded seller shop database: " + str(database_lenght) + " listings")
|
#print("Loaded seller shop database: " + str(database_lenght) + " listings")
|
||||||
|
pbar = tqdm(total=database_lenght) #print progress ba
|
||||||
compare_start_timestamp = datetime.now() #set start time for comparing
|
compare_start_timestamp = datetime.now() #set start time for comparing
|
||||||
for shop_listing_url in seller_db.all():
|
for shop_listing_url in seller_db.all():
|
||||||
#print(shop_listing_url["epid"])
|
#print(shop_listing_url["epid"])
|
||||||
|
|
||||||
for retrieve_counter in range(5):
|
for retrieve_counter in range(5):
|
||||||
try:
|
try:
|
||||||
seller_listing_data = sl.scrape_listing(shop_listing_url["epid"])
|
seller_listing_data = sl.scrape_listing(shop_listing_url["epid"])
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
#pass
|
pass
|
||||||
print("Unable to retrieve seller listing data from: " + shop_listing_url["epid"])
|
#print("Unable to retrieve seller listing data from: " + shop_listing_url["epid"])
|
||||||
|
|
||||||
if seller_listing_data:
|
if seller_listing_data:
|
||||||
print("\n\nCompare: " + seller_listing_data["title"] + " | " + str(seller_listing_data["price"]) + "€ | " + shop_listing_url["epid"])
|
#print("\n\nCompare: " + seller_listing_data["title"] + " | " + str(seller_listing_data["price"]) + "€ | " + shop_listing_url["epid"])
|
||||||
|
|
||||||
comparison_result = {
|
comparison_result = {
|
||||||
'seller_listing': seller_listing_data,
|
'seller_listing': seller_listing_data,
|
||||||
|
@ -46,7 +46,7 @@ if __name__ == "__main__":
|
||||||
}
|
}
|
||||||
|
|
||||||
competitor_listings = se.search(seller_listing_data["title"], 1)
|
competitor_listings = se.search(seller_listing_data["title"], 1)
|
||||||
print("Found " + str(len(competitor_listings)) + " listings from competitors with term: " + seller_listing_data["title"])
|
#print("Found " + str(len(competitor_listings)) + " listings from competitors with term: " + seller_listing_data["title"])
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
cheaper_listings = list()
|
cheaper_listings = list()
|
||||||
for competitor_listing_url in competitor_listings:
|
for competitor_listing_url in competitor_listings:
|
||||||
|
@ -54,7 +54,7 @@ if __name__ == "__main__":
|
||||||
#print(shop_listing_url["epid"])
|
#print(shop_listing_url["epid"])
|
||||||
|
|
||||||
if seller_db.search(Query().epid == competitor_listing_url):
|
if seller_db.search(Query().epid == competitor_listing_url):
|
||||||
print("Found listing from sellers shop --> ignore " + competitor_listing_url)
|
#print("Found listing from sellers shop --> ignore " + competitor_listing_url)
|
||||||
continue
|
continue
|
||||||
#else:
|
#else:
|
||||||
#print("not from own shop")
|
#print("not from own shop")
|
||||||
|
@ -80,16 +80,16 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
for cheaper_listing in sorted(cheaper_listings, key=lambda d: d['price']) :
|
for cheaper_listing in sorted(cheaper_listings, key=lambda d: d['price']) :
|
||||||
#print(cheaper_listing)
|
#print(cheaper_listing)
|
||||||
print("found cheaper competitor: " + str(cheaper_listing["price"]) + "€ instead: " + str(seller_listing_data["price"]) + "€ ---> " + cheaper_listing["url"])
|
#print("found cheaper competitor: " + str(cheaper_listing["price"]) + "€ instead: " + str(seller_listing_data["price"]) + "€ ---> " + cheaper_listing["url"])
|
||||||
comparison_result['competitor_listings'].append(cheaper_listing)
|
comparison_result['competitor_listings'].append(cheaper_listing)
|
||||||
if comparison_result['max_price_delta'] == 0.0:
|
if comparison_result['max_price_delta'] == 0.0:
|
||||||
comparison_result['max_price_delta'] = seller_listing_data["price"] - cheaper_listing["price"]
|
comparison_result['max_price_delta'] = seller_listing_data["price"] - cheaper_listing["price"]
|
||||||
|
|
||||||
if cheaper_listings:
|
if cheaper_listings:
|
||||||
comparison_results.append(comparison_result)
|
comparison_results.append(comparison_result)
|
||||||
|
pbar.update(1)
|
||||||
#break
|
#break
|
||||||
|
pbar.close()
|
||||||
print("\nFinished comparing! Found " + str(len(comparison_results)) + " possibly cheaper listings")
|
print("\nFinished comparing! Found " + str(len(comparison_results)) + " possibly cheaper listings")
|
||||||
|
|
||||||
now = datetime.now() # current date and time
|
now = datetime.now() # current date and time
|
||||||
|
|
Loading…
Reference in New Issue