amazon-orders 4.7.0__tar.gz → 4.8.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/CHANGELOG.md +22 -1
  2. {amazon_orders-4.7.0/amazon_orders.egg-info → amazon_orders-4.8.0}/PKG-INFO +33 -6
  3. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/README.md +32 -5
  4. {amazon_orders-4.7.0 → amazon_orders-4.8.0/amazon_orders.egg-info}/PKG-INFO +33 -6
  5. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazon_orders.egg-info/SOURCES.txt +3 -0
  6. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/__init__.py +1 -1
  7. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/cli.py +87 -4
  8. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/conf.py +40 -24
  9. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/constants.py +41 -25
  10. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/contrib/browser/playwright.py +157 -5
  11. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/contrib/waf/anticaptcha.py +1 -1
  12. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/contrib/waf/capsolver.py +2 -2
  13. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/contrib/waf/twocaptcha.py +1 -1
  14. amazon_orders-4.8.0/amazonorders/entity/gift_card_activity.py +98 -0
  15. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/entity/order.py +1 -1
  16. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/entity/shipment.py +12 -0
  17. amazon_orders-4.8.0/amazonorders/entity/tracking.py +58 -0
  18. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/forms.py +1 -1
  19. amazon_orders-4.8.0/amazonorders/gift_cards.py +148 -0
  20. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/orders.py +178 -82
  21. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/output.py +22 -0
  22. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/selectors.py +39 -3
  23. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/session.py +14 -10
  24. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/pyproject.toml +11 -0
  25. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/LICENSE +0 -0
  26. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/MANIFEST.in +0 -0
  27. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazon_orders.egg-info/dependency_links.txt +0 -0
  28. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazon_orders.egg-info/entry_points.txt +0 -0
  29. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazon_orders.egg-info/requires.txt +0 -0
  30. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazon_orders.egg-info/top_level.txt +0 -0
  31. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/banner.txt +0 -0
  32. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/contrib/__init__.py +0 -0
  33. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/contrib/browser/__init__.py +0 -0
  34. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/contrib/waf/__init__.py +0 -0
  35. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/contrib/waf/base.py +0 -0
  36. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/entity/__init__.py +0 -0
  37. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/entity/item.py +0 -0
  38. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/entity/parsable.py +0 -0
  39. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/entity/recipient.py +0 -0
  40. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/entity/seller.py +0 -0
  41. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/entity/transaction.py +0 -0
  42. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/exception.py +0 -0
  43. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/transactions.py +0 -0
  44. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/amazonorders/util.py +0 -0
  45. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/setup.cfg +0 -0
  46. {amazon_orders-4.7.0 → amazon_orders-4.8.0}/tests/testcase.py +0 -0
@@ -4,7 +4,28 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [Unreleased](https://github.com/alexdlaird/amazon-orders/compare/4.7.0...HEAD)
7
+ ## [Unreleased](https://github.com/alexdlaird/amazon-orders/compare/4.8.0...HEAD)
8
+
9
+ ## [4.8.0](https://github.com/alexdlaird/amazon-orders/compare/4.7.1...4.8.0) - 2026-10-09
10
+
11
+ ### Added
12
+
13
+ - `login --browser`, and `PlaywrightBrowserLogin`, to sign in on Amazon's own page in a browser window, so `amazon-orders` never needs to store or know your credentials.
14
+ - `Tracking` entity, `AmazonOrders.get_tracking()` and `parse_tracking()`, and `Shipment.shipment_id`, for a Shipment's carrier and tracking number.
15
+
16
+ ### Fixed
17
+
18
+ - Bug fixes and stability improvements.
19
+
20
+ ## [4.7.1](https://github.com/alexdlaird/amazon-orders/compare/4.7.0...4.7.1) - 2026-10-07
21
+
22
+ ### Added
23
+
24
+ - `AmazonGiftCards`, the `GiftCardActivity` entity, and the `gift-card-balance` and `gift-card-activity` CLI commands, for the Gift Card balance and activity.
25
+
26
+ ### Fixed
27
+
28
+ - Bug fixes and stability improvements.
8
29
 
9
30
  ## [4.7.0](https://github.com/alexdlaird/amazon-orders/compare/4.6.1...4.7.0) - 2026-10-06
10
31
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: amazon-orders
3
- Version: 4.7.0
3
+ Version: 4.8.0
4
4
  Summary: A Python library (and CLI) for Amazon order history
5
5
  Author-email: Alex Laird <contact@alexlaird.com>
6
6
  Maintainer-email: Alex Laird <contact@alexlaird.com>
@@ -85,10 +85,9 @@ Dynamic: license-file
85
85
 
86
86
  `amazon-orders` is an unofficial library that provides a Python API (and CLI) for Amazon order history, line items, and transactions.
87
87
 
88
- Only the English, `.com` version of Amazon is officially supported. Other Amazon domains can be
89
- targeted by passing `domain` to [`AmazonSession`](https://amazon-orders.readthedocs.io/api.html#amazonorders.session.AmazonSession)
90
- (or `--domain` on the CLI), and other English-based sites may work by chance — see
91
- [Known Limitations](https://amazon-orders.readthedocs.io/index.html#known-limitations) for details.
88
+ `amazon-orders` core supports Amazon's English `.com` site, validated nightly. Other English Amazon sites can be
89
+ targeted with the `domain` config option, and other languages plug in through
90
+ [language packages](https://amazon-orders.readthedocs.io/language-packages.html).
92
91
 
93
92
  > **Note:** This package works by parsing data from Amazon's consumer-facing website. A periodic build validates
94
93
  > functionality to ensure its stability, but as Amazon provides no official API to use, older versions of this
@@ -104,7 +103,7 @@ pip install amazon-orders --upgrade
104
103
 
105
104
  That's it! `amazon-orders` is now available as a package to your Python projects and from the command line.
106
105
 
107
- If pinning, be sure to use a wildcard for the [minor version](https://semver.org/) (ex. `==4.7.*`, not `==4.7.0`) to
106
+ If pinning, be sure to use a wildcard for the [minor version](https://semver.org/) (ex. `==4.8.*`, not `==4.8.0`) to
108
107
  ensure you always get the latest stable release.
109
108
 
110
109
  ## Basic Usage
@@ -141,6 +140,26 @@ the `history` CLI command), since by default it is `False` (enabling it slows do
141
140
  request for each order is necessary). Have a look at the [Order](https://amazon-orders.readthedocs.io/api.html#amazonorders.entity.order.Order) entity's docs to see what fields are only
142
141
  populated with full details.
143
142
 
143
+ ### Secure Sign-In
144
+
145
+ The most secure way to use `amazon-orders` is to sign in on Amazon's own page, in a browser window, so your password,
146
+ one-time password, and any challenge never reach `amazon-orders`:
147
+
148
+ ```sh
149
+ amazon-orders login --browser
150
+ ```
151
+
152
+ The session is persisted, so neither the CLI nor the Python API needs credentials:
153
+
154
+ ```python
155
+ from amazonorders.session import AmazonSession
156
+
157
+ amazon_session = AmazonSession()
158
+ amazon_session.login()
159
+ ```
160
+
161
+ See [Browser Automation](https://amazon-orders.readthedocs.io/browser.html#signing-in-with-a-browser) for details.
162
+
144
163
  ### Command Line Usage
145
164
 
146
165
  You can also run any command available to the main Python interface from the command line:
@@ -201,6 +220,14 @@ pip install amazon-orders[captcha]
201
220
 
202
221
  See [Login Challenges](https://amazon-orders.readthedocs.io/troubleshooting.html#login-challenges) for details.
203
222
 
223
+ ### Languages and Regions
224
+
225
+ `amazon-orders` core supports the English `.com` site, validated nightly.
226
+
227
+ - **Other English sites** (e.g. `amazon.ca`, `amazon.co.uk`): set the `domain` config option.
228
+ - **Other languages**: install a language package and set `language_package`. See
229
+ [Language Packages](https://amazon-orders.readthedocs.io/language-packages.html).
230
+
204
231
  ## Documentation
205
232
 
206
233
  For more advanced usage, `amazon-orders`'s official documentation is available
@@ -9,10 +9,9 @@
9
9
 
10
10
  `amazon-orders` is an unofficial library that provides a Python API (and CLI) for Amazon order history, line items, and transactions.
11
11
 
12
- Only the English, `.com` version of Amazon is officially supported. Other Amazon domains can be
13
- targeted by passing `domain` to [`AmazonSession`](https://amazon-orders.readthedocs.io/api.html#amazonorders.session.AmazonSession)
14
- (or `--domain` on the CLI), and other English-based sites may work by chance — see
15
- [Known Limitations](https://amazon-orders.readthedocs.io/index.html#known-limitations) for details.
12
+ `amazon-orders` core supports Amazon's English `.com` site, validated nightly. Other English Amazon sites can be
13
+ targeted with the `domain` config option, and other languages plug in through
14
+ [language packages](https://amazon-orders.readthedocs.io/language-packages.html).
16
15
 
17
16
  > **Note:** This package works by parsing data from Amazon's consumer-facing website. A periodic build validates
18
17
  > functionality to ensure its stability, but as Amazon provides no official API to use, older versions of this
@@ -28,7 +27,7 @@ pip install amazon-orders --upgrade
28
27
 
29
28
  That's it! `amazon-orders` is now available as a package to your Python projects and from the command line.
30
29
 
31
- If pinning, be sure to use a wildcard for the [minor version](https://semver.org/) (ex. `==4.7.*`, not `==4.7.0`) to
30
+ If pinning, be sure to use a wildcard for the [minor version](https://semver.org/) (ex. `==4.8.*`, not `==4.8.0`) to
32
31
  ensure you always get the latest stable release.
33
32
 
34
33
  ## Basic Usage
@@ -65,6 +64,26 @@ the `history` CLI command), since by default it is `False` (enabling it slows do
65
64
  request for each order is necessary). Have a look at the [Order](https://amazon-orders.readthedocs.io/api.html#amazonorders.entity.order.Order) entity's docs to see what fields are only
66
65
  populated with full details.
67
66
 
67
+ ### Secure Sign-In
68
+
69
+ The most secure way to use `amazon-orders` is to sign in on Amazon's own page, in a browser window, so your password,
70
+ one-time password, and any challenge never reach `amazon-orders`:
71
+
72
+ ```sh
73
+ amazon-orders login --browser
74
+ ```
75
+
76
+ The session is persisted, so neither the CLI nor the Python API needs credentials:
77
+
78
+ ```python
79
+ from amazonorders.session import AmazonSession
80
+
81
+ amazon_session = AmazonSession()
82
+ amazon_session.login()
83
+ ```
84
+
85
+ See [Browser Automation](https://amazon-orders.readthedocs.io/browser.html#signing-in-with-a-browser) for details.
86
+
68
87
  ### Command Line Usage
69
88
 
70
89
  You can also run any command available to the main Python interface from the command line:
@@ -125,6 +144,14 @@ pip install amazon-orders[captcha]
125
144
 
126
145
  See [Login Challenges](https://amazon-orders.readthedocs.io/troubleshooting.html#login-challenges) for details.
127
146
 
147
+ ### Languages and Regions
148
+
149
+ `amazon-orders` core supports the English `.com` site, validated nightly.
150
+
151
+ - **Other English sites** (e.g. `amazon.ca`, `amazon.co.uk`): set the `domain` config option.
152
+ - **Other languages**: install a language package and set `language_package`. See
153
+ [Language Packages](https://amazon-orders.readthedocs.io/language-packages.html).
154
+
128
155
  ## Documentation
129
156
 
130
157
  For more advanced usage, `amazon-orders`'s official documentation is available
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: amazon-orders
3
- Version: 4.7.0
3
+ Version: 4.8.0
4
4
  Summary: A Python library (and CLI) for Amazon order history
5
5
  Author-email: Alex Laird <contact@alexlaird.com>
6
6
  Maintainer-email: Alex Laird <contact@alexlaird.com>
@@ -85,10 +85,9 @@ Dynamic: license-file
85
85
 
86
86
  `amazon-orders` is an unofficial library that provides a Python API (and CLI) for Amazon order history, line items, and transactions.
87
87
 
88
- Only the English, `.com` version of Amazon is officially supported. Other Amazon domains can be
89
- targeted by passing `domain` to [`AmazonSession`](https://amazon-orders.readthedocs.io/api.html#amazonorders.session.AmazonSession)
90
- (or `--domain` on the CLI), and other English-based sites may work by chance — see
91
- [Known Limitations](https://amazon-orders.readthedocs.io/index.html#known-limitations) for details.
88
+ `amazon-orders` core supports Amazon's English `.com` site, validated nightly. Other English Amazon sites can be
89
+ targeted with the `domain` config option, and other languages plug in through
90
+ [language packages](https://amazon-orders.readthedocs.io/language-packages.html).
92
91
 
93
92
  > **Note:** This package works by parsing data from Amazon's consumer-facing website. A periodic build validates
94
93
  > functionality to ensure its stability, but as Amazon provides no official API to use, older versions of this
@@ -104,7 +103,7 @@ pip install amazon-orders --upgrade
104
103
 
105
104
  That's it! `amazon-orders` is now available as a package to your Python projects and from the command line.
106
105
 
107
- If pinning, be sure to use a wildcard for the [minor version](https://semver.org/) (ex. `==4.7.*`, not `==4.7.0`) to
106
+ If pinning, be sure to use a wildcard for the [minor version](https://semver.org/) (ex. `==4.8.*`, not `==4.8.0`) to
108
107
  ensure you always get the latest stable release.
109
108
 
110
109
  ## Basic Usage
@@ -141,6 +140,26 @@ the `history` CLI command), since by default it is `False` (enabling it slows do
141
140
  request for each order is necessary). Have a look at the [Order](https://amazon-orders.readthedocs.io/api.html#amazonorders.entity.order.Order) entity's docs to see what fields are only
142
141
  populated with full details.
143
142
 
143
+ ### Secure Sign-In
144
+
145
+ The most secure way to use `amazon-orders` is to sign in on Amazon's own page, in a browser window, so your password,
146
+ one-time password, and any challenge never reach `amazon-orders`:
147
+
148
+ ```sh
149
+ amazon-orders login --browser
150
+ ```
151
+
152
+ The session is persisted, so neither the CLI nor the Python API needs credentials:
153
+
154
+ ```python
155
+ from amazonorders.session import AmazonSession
156
+
157
+ amazon_session = AmazonSession()
158
+ amazon_session.login()
159
+ ```
160
+
161
+ See [Browser Automation](https://amazon-orders.readthedocs.io/browser.html#signing-in-with-a-browser) for details.
162
+
144
163
  ### Command Line Usage
145
164
 
146
165
  You can also run any command available to the main Python interface from the command line:
@@ -201,6 +220,14 @@ pip install amazon-orders[captcha]
201
220
 
202
221
  See [Login Challenges](https://amazon-orders.readthedocs.io/troubleshooting.html#login-challenges) for details.
203
222
 
223
+ ### Languages and Regions
224
+
225
+ `amazon-orders` core supports the English `.com` site, validated nightly.
226
+
227
+ - **Other English sites** (e.g. `amazon.ca`, `amazon.co.uk`): set the `domain` config option.
228
+ - **Other languages**: install a language package and set `language_package`. See
229
+ [Language Packages](https://amazon-orders.readthedocs.io/language-packages.html).
230
+
204
231
  ## Documentation
205
232
 
206
233
  For more advanced usage, `amazon-orders`'s official documentation is available
@@ -16,6 +16,7 @@ amazonorders/conf.py
16
16
  amazonorders/constants.py
17
17
  amazonorders/exception.py
18
18
  amazonorders/forms.py
19
+ amazonorders/gift_cards.py
19
20
  amazonorders/orders.py
20
21
  amazonorders/output.py
21
22
  amazonorders/selectors.py
@@ -31,11 +32,13 @@ amazonorders/contrib/waf/base.py
31
32
  amazonorders/contrib/waf/capsolver.py
32
33
  amazonorders/contrib/waf/twocaptcha.py
33
34
  amazonorders/entity/__init__.py
35
+ amazonorders/entity/gift_card_activity.py
34
36
  amazonorders/entity/item.py
35
37
  amazonorders/entity/order.py
36
38
  amazonorders/entity/parsable.py
37
39
  amazonorders/entity/recipient.py
38
40
  amazonorders/entity/seller.py
39
41
  amazonorders/entity/shipment.py
42
+ amazonorders/entity/tracking.py
40
43
  amazonorders/entity/transaction.py
41
44
  tests/testcase.py
@@ -1,3 +1,3 @@
1
1
  __copyright__ = "Copyright (c) 2024-2025 Alex Laird"
2
2
  __license__ = "MIT"
3
- __version__ = "4.7.0"
3
+ __version__ = "4.8.0"
@@ -15,7 +15,9 @@ from click.core import Context
15
15
 
16
16
  from amazonorders import __version__, util
17
17
  from amazonorders.conf import AmazonOrdersConfig
18
+ from amazonorders.contrib.browser.playwright import PlaywrightBrowserLogin
18
19
  from amazonorders.exception import AmazonOrdersError, AmazonOrdersAuthError, AmazonOrdersAuthRedirectError
20
+ from amazonorders.gift_cards import AmazonGiftCards
19
21
  from amazonorders.orders import AmazonOrders
20
22
  from amazonorders.output import OutputFormatter
21
23
  from amazonorders.session import AmazonSession, IODefault
@@ -71,7 +73,8 @@ def amazon_orders_cli(ctx: Context,
71
73
  to ensure its stability, but as Amazon provides no official API to use, this package may break at any time. Check
72
74
  for updates regularly to ensure you always have the latest stable release.
73
75
 
74
- This package only officially supports the English, .com version of Amazon.
76
+ This package supports the English, .com version of Amazon. Other English Amazon sites can be targeted with
77
+ --domain, and other languages are supported through language packages.
75
78
 
76
79
  Documentation can be found at https://amazon-orders.readthedocs.io.
77
80
  """
@@ -314,7 +317,7 @@ def order_transactions(ctx: Context,
314
317
  help="The number of days of Transactions to get.")
315
318
  @click.option("-o", "--output", type=click.Choice(OutputFormatter.OUTPUT_FORMATS), default="text",
316
319
  help="The output format. Defaults to text.")
317
- def transactions(ctx: Context, **kwargs: Any):
320
+ def transactions(ctx: Context, **kwargs: Any) -> None:
318
321
  """
319
322
  Get Amazon Transaction history for a given number of days.
320
323
  """
@@ -353,6 +356,76 @@ Transaction History for {days} days
353
356
  ctx.fail(str(e))
354
357
 
355
358
 
359
+ @amazon_orders_cli.command()
360
+ @click.pass_context
361
+ def gift_card_balance(ctx: Context) -> None:
362
+ """
363
+ Get the current Amazon Gift Card balance.
364
+ """
365
+ amazon_session = ctx.obj["amazon_session"]
366
+
367
+ try:
368
+ _authenticate(amazon_session)
369
+
370
+ config = ctx.obj["conf"]
371
+ amazon_gift_cards = AmazonGiftCards(amazon_session,
372
+ config=config)
373
+
374
+ balance = amazon_gift_cards.get_balance()
375
+
376
+ click.echo(f"Gift Card Balance: {config.constants.format_currency(balance)}")
377
+ except AmazonOrdersAuthRedirectError:
378
+ _prompt_to_reauth_flow()
379
+ except AmazonOrdersError as e:
380
+ logger.debug("An error occurred.", exc_info=True)
381
+ ctx.fail(str(e))
382
+
383
+
384
+ @amazon_orders_cli.command()
385
+ @click.pass_context
386
+ @click.option("--days", default=365,
387
+ help="The number of days of Gift Card activity to get.")
388
+ @click.option("-o", "--output", type=click.Choice(OutputFormatter.OUTPUT_FORMATS), default="text",
389
+ help="The output format. Defaults to text.")
390
+ def gift_card_activity(ctx: Context, **kwargs: Any) -> None:
391
+ """
392
+ Get Amazon Gift Card activity for a given number of days.
393
+ """
394
+ amazon_session = ctx.obj["amazon_session"]
395
+
396
+ try:
397
+ _authenticate(amazon_session)
398
+
399
+ days = kwargs["days"]
400
+ output = kwargs["output"]
401
+
402
+ click.echo(
403
+ """-----------------------------------------------------------------------
404
+ Gift Card Activity for {days} days
405
+ -----------------------------------------------------------------------\n""".format(days=days), err=True
406
+ )
407
+ click.echo("Info: Fetching Gift Card activity, this might take a minute ...", err=True)
408
+
409
+ config = ctx.obj["conf"]
410
+ amazon_gift_cards = AmazonGiftCards(amazon_session,
411
+ config=config)
412
+
413
+ start_time = time.time()
414
+ activity = amazon_gift_cards.get_gift_card_activity(days=days)
415
+ end_time = time.time()
416
+
417
+ click.echo(config.output_cls(config).format(activity, output))
418
+
419
+ click.echo(
420
+ "... {total} Gift Card activity entries parsed in {time} seconds.\n".format(
421
+ total=len(activity), time=int(end_time - start_time)), err=True)
422
+ except AmazonOrdersAuthRedirectError:
423
+ _prompt_to_reauth_flow()
424
+ except AmazonOrdersError as e:
425
+ logger.debug("An error occurred.", exc_info=True)
426
+ ctx.fail(str(e))
427
+
428
+
356
429
  @amazon_orders_cli.command(short_help="Check if a persisted session exists.")
357
430
  @click.pass_context
358
431
  def check_session(ctx: Context) -> None:
@@ -368,7 +441,10 @@ def check_session(ctx: Context) -> None:
368
441
 
369
442
  @amazon_orders_cli.command()
370
443
  @click.pass_context
371
- def login(ctx: Context) -> None:
444
+ @click.option("--browser", is_flag=True, default=False,
445
+ help="Sign in with a browser window, so credentials are entered on Amazon's own page and never reach "
446
+ "amazon-orders. Requires the browser extra.")
447
+ def login(ctx: Context, **kwargs: Any) -> None:
372
448
  """
373
449
  Login to establish an Amazon session and cookies.
374
450
  """
@@ -378,7 +454,14 @@ def login(ctx: Context) -> None:
378
454
  click.echo(
379
455
  "Info: A persisted session exists. Call the `logout` command first to change users.\n")
380
456
  else:
381
- _authenticate(amazon_session)
457
+ try:
458
+ if kwargs["browser"]:
459
+ PlaywrightBrowserLogin(amazon_session).login()
460
+ else:
461
+ _authenticate(amazon_session)
462
+ except AmazonOrdersError as e:
463
+ logger.debug("An error occurred.", exc_info=True)
464
+ ctx.fail(str(e))
382
465
 
383
466
  click.echo("Info: Successfully logged in to Amazon, session persisted.\n")
384
467
 
@@ -51,6 +51,7 @@ class AmazonOrdersConfig:
51
51
 
52
52
  self._data: Dict[str, Any] = self._default_data()
53
53
  self._resolved_classes: Dict[str, Any] = {}
54
+ self._assigned_classes: Dict[str, Any] = {}
54
55
 
55
56
  with config_file_lock:
56
57
  if os.path.exists(self.config_path):
@@ -155,6 +156,9 @@ class AmazonOrdersConfig:
155
156
  :return: The resolved class.
156
157
  :raises AmazonOrdersError: If the configured class path cannot be imported.
157
158
  """
159
+ if key in self._assigned_classes:
160
+ return self._assigned_classes[key]
161
+
158
162
  if key not in self._resolved_classes:
159
163
  class_path = self._class_path(key)
160
164
  class_split = class_path.split(".")
@@ -215,7 +219,28 @@ class AmazonOrdersConfig:
215
219
  :param key: The config key naming the class.
216
220
  :param value: The class to use.
217
221
  """
218
- self._resolved_classes[key] = value
222
+ self._assigned_classes[key] = value
223
+
224
+ def _validate_bs4_parser(self) -> None:
225
+ try:
226
+ BeautifulSoup("", str(self._data["bs4_parser"]))
227
+ except FeatureNotFound:
228
+ logger.warning(
229
+ f"Configured bs4_parser '{self._data['bs4_parser']}' is unavailable; "
230
+ f"using the default 'html.parser'. To use it, install the parser "
231
+ f"(e.g. `pip install amazon-orders[lxml]`)."
232
+ )
233
+ self._data["bs4_parser"] = "html.parser"
234
+
235
+ def _instantiate_constants(self) -> Any:
236
+ constants_class_split = self._class_path("constants_class").split(".")
237
+ constants_cls = util.load_class(constants_class_split[:-1], constants_class_split[-1])
238
+ # Pass ``self`` only when the constants class accepts a config arg, to keep backward
239
+ # compatibility with existing zero-arg ``constants_class`` subclasses.
240
+ init_params = inspect.signature(constants_cls.__init__).parameters
241
+ if len(init_params) > 1:
242
+ return constants_cls(self)
243
+ return constants_cls()
219
244
 
220
245
  @property
221
246
  def order_cls(self) -> Any:
@@ -277,27 +302,6 @@ class AmazonOrdersConfig:
277
302
  value: Any) -> None:
278
303
  self._set_class("transactions_page_class", value)
279
304
 
280
- def _validate_bs4_parser(self) -> None:
281
- try:
282
- BeautifulSoup("", str(self._data["bs4_parser"]))
283
- except FeatureNotFound:
284
- logger.debug(
285
- f"Configured bs4_parser '{self._data['bs4_parser']}' is unavailable; "
286
- f"using the default 'html.parser'. To use it, install the parser "
287
- f"(e.g. `pip install amazon-orders[lxml]`)."
288
- )
289
- self._data["bs4_parser"] = "html.parser"
290
-
291
- def _instantiate_constants(self) -> Any:
292
- constants_class_split = self._class_path("constants_class").split(".")
293
- constants_cls = util.load_class(constants_class_split[:-1], constants_class_split[-1])
294
- # Pass ``self`` only when the constants class accepts a config arg, to keep backward
295
- # compatibility with existing zero-arg ``constants_class`` subclasses.
296
- init_params = inspect.signature(constants_cls.__init__).parameters
297
- if len(init_params) > 1:
298
- return constants_cls(self)
299
- return constants_cls()
300
-
301
305
  def set_domain(self,
302
306
  domain: str) -> None:
303
307
  """
@@ -318,11 +322,11 @@ class AmazonOrdersConfig:
318
322
  return key in self._data
319
323
 
320
324
  def __getstate__(self) -> Dict[str, Any]:
321
- return self._data
325
+ return {"config_path": self.config_path, "_data": self._data, "_assigned_classes": self._assigned_classes}
322
326
 
323
327
  def __setstate__(self,
324
328
  state: Dict[str, Any]) -> None:
325
- self._data = state
329
+ self.__dict__.update(state)
326
330
  self._resolved_classes = {}
327
331
  self._load_classes()
328
332
 
@@ -338,7 +342,19 @@ class AmazonOrdersConfig:
338
342
  :param value: The new value.
339
343
  :param save: ``True`` if the config should be persisted.
340
344
  """
345
+ previous_data = dict(self._data)
341
346
  self._data[key] = value
347
+ try:
348
+ self._validate_bs4_parser()
349
+ self._validate_class_paths()
350
+ self._load_classes()
351
+ except (AmazonOrdersError, AttributeError, ImportError):
352
+ self._data = previous_data
353
+ self._load_classes()
354
+ raise
355
+
356
+ self._assigned_classes.pop(key, None)
357
+ self._resolved_classes = {}
342
358
 
343
359
  if save:
344
360
  self.save()
@@ -96,15 +96,6 @@ _REGION_AUTH_COOKIES = {
96
96
  }
97
97
 
98
98
 
99
- def _normalize_base_url(value: str) -> str:
100
- value = value.strip().rstrip("/")
101
- if value.startswith(("http://", "https://")):
102
- return value
103
- if value.startswith("www."):
104
- return f"https://{value}"
105
- return f"https://www.{value}"
106
-
107
-
108
99
  class Constants:
109
100
  """
110
101
  A class containing useful constants. Extend and override with ``constants_class`` in the config:
@@ -126,8 +117,8 @@ class Constants:
126
117
  2. The ``AMAZON_BASE_URL`` environment variable.
127
118
  3. The default, ``amazon.com``.
128
119
 
129
- Only the English, ``.com`` site is officially supported. Other domains may work; subclass and set
130
- ``constants_class`` to override any values a particular site requires.
120
+ ``amazon-orders`` core supports the English ``.com`` site; subclass and set ``constants_class`` to override any
121
+ value another site requires.
131
122
  """
132
123
 
133
124
  ##########################################################################
@@ -161,6 +152,11 @@ class Constants:
161
152
  HISTORY_FILTER_QUERY_PARAM = "timeFilter"
162
153
  ORDER_FILTER_QUERY_PARAM = "orderFilter"
163
154
  WHOLE_FOODS_DETAILS_ROUTES = ["/fopo/order-details", "/wholefoodsmarket/receipts/order/"]
155
+ TRACKING_ROUTE = "/progress-tracker/package"
156
+ TRACKING_URL = f"{BASE_URL}{TRACKING_ROUTE}"
157
+ TRACKING_ORDER_ID_QUERY_PARAM = "orderId"
158
+ SHIPMENT_ID_QUERY_PARAM = "shipmentId"
159
+ TRACKING_PACKAGE_INDEX_QUERY_PARAM = "packageIndex"
164
160
 
165
161
  ##########################################################################
166
162
  # URLs for Transactions
@@ -169,6 +165,13 @@ class Constants:
169
165
  TRANSACTION_HISTORY_ROUTE = "/cpe/yourpayments/transactions"
170
166
  TRANSACTION_HISTORY_URL = f"{BASE_URL}{TRANSACTION_HISTORY_ROUTE}"
171
167
 
168
+ ##########################################################################
169
+ # URLs for Gift Cards
170
+ ##########################################################################
171
+
172
+ GIFT_CARD_BALANCE_ROUTE = "/gc/balance"
173
+ GIFT_CARD_BALANCE_URL = f"{BASE_URL}{GIFT_CARD_BALANCE_ROUTE}"
174
+
172
175
  ##########################################################################
173
176
  # Headers
174
177
  ##########################################################################
@@ -202,7 +205,7 @@ class Constants:
202
205
  ACIC_CHALLENGE_PATH = "/ax/aaut/verify/ap/challenge"
203
206
 
204
207
  ##########################################################################
205
- # Number and Currency Formats
208
+ # Formats
206
209
  ##########################################################################
207
210
 
208
211
  DECIMAL_SEPARATOR = "."
@@ -213,7 +216,9 @@ class Constants:
213
216
  CURRENCY_SYMBOL = os.environ.get("AMAZON_CURRENCY_SYMBOL", "$")
214
217
  CURRENCY_FORMAT = "{symbol}{amount}"
215
218
  CURRENCY_FREE_TEXT = "free"
216
- ORDER_NUMBER_REGEX = r"(?<![A-Z0-9-])(?:[A-Z0-9]{3}-\d{7}-\d{7}|\d{19})(?![A-Z0-9-])"
219
+ #: Order numbers by shape: ``111-…`` and digital ``D01-…`` IDs, older ``4000-…`` IDs (still listed on
220
+ #: Gift Card activity from around 2015), and 19-digit IDs.
221
+ ORDER_NUMBER_REGEX = r"(?<![A-Z0-9-])(?:[A-Z0-9]{3}-\d{7}-\d{7}|\d{4}-\d{6}-\d{7}|\d{19})(?![A-Z0-9-])"
217
222
 
218
223
  def __init__(self,
219
224
  config: Optional["AmazonOrdersConfig"] = None) -> None:
@@ -263,7 +268,7 @@ class Constants:
263
268
 
264
269
  :param domain: The Amazon domain (e.g. ``amazon.com.au``) or full URL (e.g. ``https://www.amazon.com.au``).
265
270
  """
266
- base_url = _normalize_base_url(domain)
271
+ base_url = self._normalize_base_url(domain)
267
272
 
268
273
  host = urlparse(base_url).netloc.lower().split(":")[0]
269
274
  if host.startswith("www."):
@@ -288,7 +293,9 @@ class Constants:
288
293
  self.ORDER_HISTORY_URL = f"{base_url}/your-orders/orders"
289
294
  self.ORDER_DETAILS_URL = f"{base_url}/gp/your-account/order-details"
290
295
  self.ORDER_INVOICE_URL = f"{base_url}/gp/css/summary/print.html"
296
+ self.TRACKING_URL = f"{base_url}{self.TRACKING_ROUTE}"
291
297
  self.TRANSACTION_HISTORY_URL = f"{base_url}{self.TRANSACTION_HISTORY_ROUTE}"
298
+ self.GIFT_CARD_BALANCE_URL = f"{base_url}{self.GIFT_CARD_BALANCE_ROUTE}"
292
299
 
293
300
  headers = dict(vars(self).get("BASE_HEADERS", type(self).BASE_HEADERS))
294
301
  headers["Origin"] = base_url
@@ -307,6 +314,15 @@ class Constants:
307
314
  type(self).COOKIES_SET_WHEN_AUTHENTICATED == Constants.COOKIES_SET_WHEN_AUTHENTICATED):
308
315
  self.COOKIES_SET_WHEN_AUTHENTICATED = [_REGION_AUTH_COOKIES[tld]]
309
316
 
317
+ @staticmethod
318
+ def _normalize_base_url(value: str) -> str:
319
+ value = value.strip().rstrip("/")
320
+ if value.startswith(("http://", "https://")):
321
+ return value
322
+ if value.startswith("www."):
323
+ return f"https://{value}"
324
+ return f"https://www.{value}"
325
+
310
326
  def format_currency(self,
311
327
  amount: float) -> str:
312
328
  """
@@ -366,17 +382,6 @@ class Constants:
366
382
 
367
383
  return currency
368
384
 
369
- def parse_order_number(self,
370
- value: str) -> Optional[str]:
371
- """
372
- Find an Order number, as matched by :attr:`ORDER_NUMBER_REGEX`, in text from the page.
373
-
374
- :param value: The text containing the Order number.
375
- :return: The Order number, or ``None`` if the text does not contain one.
376
- """
377
- match = re.search(self.ORDER_NUMBER_REGEX, value)
378
- return match.group(0) if match else None
379
-
380
385
  def parse_date(self,
381
386
  value: Optional[str],
382
387
  fuzzy: bool = False) -> Optional[date]:
@@ -401,3 +406,14 @@ class Constants:
401
406
  :return: The number, or ``None`` if ``pattern`` does not match.
402
407
  """
403
408
  return util.to_count(value, pattern)
409
+
410
+ def parse_order_number(self,
411
+ value: str) -> Optional[str]:
412
+ """
413
+ Find an Order number, as matched by :attr:`ORDER_NUMBER_REGEX`, in text from the page.
414
+
415
+ :param value: The text containing the Order number.
416
+ :return: The Order number, or ``None`` if the text does not contain one.
417
+ """
418
+ match = re.search(self.ORDER_NUMBER_REGEX, value)
419
+ return match.group(0) if match else None