Im currently coding a comprehension where I check for fruits in KG (as example) that are in stock in a webshop. The values can be between 1-10KG and that some of the values (KG) might not be in stock but could be restocked after a while.
What I have been trying to do is to print out if we find a restock. We should print it out and say that "There is a restock" and then continue to compere to see if there is more restock.
As for now I have done a mock-up data of what it could look like:
import random
import time
""" # Mock-up of a requests values that is being scraped"""
firstReq = []
for _ in range(random.randint(1, 5)):
firstReq.append(random.randint(1, 10))
while True:
""" # Mock-up of a requests values that is being scraped"""
newReq = [] # I have created an example for random values - The meaning here is that I will later on scrape values through requests.
for _ in range(random.randint(1, 5)):
newReq.append(random.randint(1, 10))
if len(newReq) > len(firstReq):
print("New value has been uploaded to the page")
newReq = firstReq
else:
print("There is more values in firstReq than in newReq")
time.sleep(2)
newReq = firstReq
However my concern is that I dont think comparing the length of found KG on the website could be a good way because an example could be if 2KG is already in stock. That means we have already 1 In-stock and we continue to see if there is new restock coming. (We don't care if it gets less in stock, only when restocked however!) and lets say that 2KG gets sold out but a 4KG gets restock, with the code I have done, this will still think there is 1 In-stock and I will then miss the 4KG restock.
I wonder how I can be able to print out whenever there has happend a restock for a value?
Aucun commentaire:
Enregistrer un commentaire