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
|
||||
import urllib3
|
||||
import sys
|
||||
from tqdm import tqdm
|
||||
import scrape_listing as sl
|
||||
import search_eBay as se
|
||||
import export_html as exhtml
|
||||
|
@ -22,22 +23,21 @@ if __name__ == "__main__":
|
|||
if database_lenght == 0:
|
||||
print("Unable to load seller shop database!")
|
||||
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
|
||||
for shop_listing_url in seller_db.all():
|
||||
#print(shop_listing_url["epid"])
|
||||
|
||||
for retrieve_counter in range(5):
|
||||
try:
|
||||
seller_listing_data = sl.scrape_listing(shop_listing_url["epid"])
|
||||
break
|
||||
except:
|
||||
#pass
|
||||
print("Unable to retrieve seller listing data from: " + shop_listing_url["epid"])
|
||||
pass
|
||||
#print("Unable to retrieve seller listing data from: " + shop_listing_url["epid"])
|
||||
|
||||
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 = {
|
||||
'seller_listing': seller_listing_data,
|
||||
|
@ -46,7 +46,7 @@ if __name__ == "__main__":
|
|||
}
|
||||
|
||||
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()
|
||||
cheaper_listings = list()
|
||||
for competitor_listing_url in competitor_listings:
|
||||
|
@ -54,7 +54,7 @@ if __name__ == "__main__":
|
|||
#print(shop_listing_url["epid"])
|
||||
|
||||
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
|
||||
#else:
|
||||
#print("not from own shop")
|
||||
|
@ -80,16 +80,16 @@ if __name__ == "__main__":
|
|||
|
||||
for cheaper_listing in sorted(cheaper_listings, key=lambda d: d['price']) :
|
||||
#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)
|
||||
if comparison_result['max_price_delta'] == 0.0:
|
||||
comparison_result['max_price_delta'] = seller_listing_data["price"] - cheaper_listing["price"]
|
||||
|
||||
if cheaper_listings:
|
||||
comparison_results.append(comparison_result)
|
||||
|
||||
pbar.update(1)
|
||||
#break
|
||||
|
||||
pbar.close()
|
||||
print("\nFinished comparing! Found " + str(len(comparison_results)) + " possibly cheaper listings")
|
||||
|
||||
now = datetime.now() # current date and time
|
||||
|
|
Loading…
Reference in New Issue