Strip3s / PhoenixBot

Phoenix Bot - A Bird Bot Resurrection
MIT License
263 stars 113 forks source link

[BUG] walmart.py has ambiguous condition #69

Open GoTTi74 opened 3 years ago

GoTTi74 commented 3 years ago

Expected Behavior

walmart.py should only consider "add to cart" if the item is actually on stock.

Actual Behaviour

On line 69 you have: if "add to cart" in r.text.lower():

Depending on the item you look up, "r.text" contains a string "add to cart" even if the item is out of stock because the full string is: <span>Why can’t I add to cart</span>

So, even if an item is out of stock, the condition is met and the script tries to add the item to the cart.

Repro Steps

  1. Create a task with an URL that is currently out of stock (e.g. https://www.walmart.com/ip/PlayStation-5-Console/363472942)
  2. Start the task
  3. PhoenixBot tries to "Add to Basket"

Additional Context

Instead of this code if "add to cart" in r.text.lower():

I was able to workaround using this because the capitalization is different: if "Add to cart" in r.text:

The better alternative is to parse the response (r) for "itemprop="availability" and the response should be one of those:

href="//schema.org/OutOfStock" href="//schema.org/InStock"

So, adding something like this: availability = doc.xpath('//link[@itemprop="availability"]/@href')[0]

with an appropriate condition might help...