alexdlaird / amazon-orders

A CLI and library for interacting with Amazon order history
https://amazon-orders.readthedocs.io/en/latest
MIT License
14 stars 7 forks source link

Returns no orders when more than zero were expected. #10

Closed JamesOsborn-SE closed 8 months ago

JamesOsborn-SE commented 8 months ago

Acknowledgements

Operating System

EndeavourOS

Python Version

3.11

amazon-orders Version

1.0.6

Describe the Bug

from amazonorders.session import AmazonSession
from amazonorders.orders import AmazonOrders
import csv
import os
email = os.environ['AMAZON_EMAIL']
password = os.environ['AMAZON_PASSWORD']
amazon_session = AmazonSession(email, password)

amazon_session.login()

amazon_orders = AmazonOrders(amazon_session)
orders = amazon_orders.get_order_history(year=2023)
print(orders)

The above prints [] I wrote the file out in the get_orders_history/orders.py

        while next_page:
            self.amazon_session.get(next_page)
            response_parsed = self.amazon_session.last_response_parsed
            with open("idk.hml", 'w', newline='') as f:
                f.write(str(response_parsed))

It looks like the expected HTML is very different from what it gets back. There is no "order-card" but there is a "js-order-card"

I've not use beautiful soup much, so I'm not familiar with the selector stuffs.

FYI, PyPI only has version 1.0.4

Steps to Reproduce

Run code with an account that has orders in 2023.

Expected Behavior

To pull all the orders from 2023

alexdlaird commented 8 months ago

I have a few accounts with data in 2023, so that can't be it. Without an example page, it's going to be difficult for me to help resolve the issue. However, my page has both order-card and js-order-card.

There is a variable in orders.py named ORDER_HISTORY_CARD_SELECTOR, that selects the div. It defaults to div[class*='order-card']:has(script). Try changing its value from your code (before you instantiate an AmazonOrders class) to div[class*='js-order-card']:has(script) instead.

Also, can you try passing debug=True when instantiating AmazonSession and AmazonOrders? I wonder if that'll show us anything interesting.

JamesOsborn-SE commented 8 months ago

I can try to sanitize the HTML. I tried the above, but the result was the same. If I get rid of :has(script) it spits out a bunch of parsing errors but gets the orders and the items.

example of a parsing error:

When building Order, `recipient` could not be parsed.
Traceback (most recent call last):
  File "/home/james/repos/amazon-orders-to-csv/venv/lib/python3.11/site-packages/amazonorders/entity/parsable.py", line 38, in safe_parse
    return parse_function()
           ^^^^^^^^^^^^^^^^
  File "/home/james/repos/amazon-orders-to-csv/venv/lib/python3.11/site-packages/amazonorders/entity/order.py", line 139, in _parse_recipient
    id=lambda value: value and value.startswith("shipToInsertionNode")).attrs[
                                                                        ^^^^^
AttributeError: 'NoneType' object has no attribute 'attrs'
alexdlaird commented 8 months ago

I have seen that error before, when I switched from using the find() method to the select() method. When I did that, I actually saw two of every order on the page—I believe one comes from the Githubissues.

  • Githubissues is a development platform for aggregating issues.