Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] walmart.py has ambiguous condition #69

Open
GoTTi74 opened this issue Dec 4, 2020 · 0 comments
Open

[BUG] walmart.py has ambiguous condition #69

GoTTi74 opened this issue Dec 4, 2020 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@GoTTi74
Copy link

GoTTi74 commented Dec 4, 2020

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...

@GoTTi74 GoTTi74 added the bug Something isn't working label Dec 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants