Skip to content

Support for other Albertson's stores, like Jewel #72

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

Open
johnmyrda opened this issue Jan 27, 2023 · 3 comments
Open

Support for other Albertson's stores, like Jewel #72

johnmyrda opened this issue Jan 27, 2023 · 3 comments

Comments

@johnmyrda
Copy link

Hi @smkent , I love this project. However, I've moved away from Safeway-land and now live near Jewel-Osco. This application clips most but not all of my Just4U coupons.

I updated the URLs within client.py and session.py and was able to get the application to clip all of them. While I am happy maintaining my own local branch of this code, it would be neat if this application could support all Albertson's stores, like Jewel and Vons and others.

Here's the diff of the changes I made to get my Jewel coupons working.

diff --git a/safeway_coupons/client.py b/safeway_coupons/client.py
index 19a1f5e..9f6784a 100644
--- a/safeway_coupons/client.py
+++ b/safeway_coupons/client.py
@@ -26,7 +26,7 @@ class SafewayClient(BaseSession):
     def get_offers(self) -> List[Offer]:
         try:
             response = self.requests.get(
-                "https://www.safeway.com/abs/pub/xapi"
+                "https://www.jewelosco.com/abs/pub/xapi"
                 "/offers/companiongalleryoffer"
                 f"?storeId={self.session.store_id}"
                 f"&rand={random.randrange(100000,999999)}",
@@ -41,7 +41,7 @@ class SafewayClient(BaseSession):
         response: Optional[requests.Response] = None
         try:
             response = self.requests.post(
-                "https://www.safeway.com/abs/pub/web/j4u/api/offers/clip"
+                "https://www.jewelosco.com/abs/pub/web/j4u/api/offers/clip"
                 f"?storeId={self.session.store_id}",
                 data=json.dumps(request.to_dict(encode_json=True)),
                 headers={"Content-Type": "application/json"},
diff --git a/safeway_coupons/session.py b/safeway_coupons/session.py
index 30ccdeb..ee9ed0e 100644
--- a/safeway_coupons/session.py
+++ b/safeway_coupons/session.py
@@ -15,7 +15,7 @@ AUTHORIZE_URL = (

 OAUTH_CLIENT_ID = "0oap6ku01XJqIRdl42p6"
 OAUTH_REDIRECT_URI = (
-    "https://www.safeway.com/bin/safeway/unified/sso/authorize"
+    "https://www.jewelosco.com/bin/safeway/unified/sso/authorize"
 )
@johnmyrda
Copy link
Author

Here's a quick PR that adds support for arbitrary store urls - johnmyrda#1

I don't know your policy on contributors, so I made the PR against my own fork.

@smkent
Copy link
Owner

smkent commented Jan 29, 2023

Hi @johnmyrda, thanks for the note! I am delighted to hear you find this useful and want to contribute.

Supporting more Albertson's brands is a great idea. A good way to do that would be to add another command line argument to select the brand to connect to, e.g.:

safeway-coupons --brand jewel-osco [...]

We could create a new file constants.py or brands.py with an enumeration of supported brand names/values/URLs. app.py's ArgumentParser could use that enumeration to validate command line options, and client.py's SafewayClient could also use it to get the URLs for the chosen brand.

@johnmyrda
Copy link
Author

Thanks @smkent! I intended for the above PR to act as a proof of concept, and I'm glad you appreciated it.

I like the idea of enumerating valid brands - very user friendly. The downside of enumeration is that the brand list would have to be maintained and Albertsons owns A LOT of supermarket chains. A hybrid approach where it's possible to select the brand but also override the URL as an advanced option would be the most flexible, but I understand not wanting to let users enter arbitrary URLs since it's very easy to mess up.

I created 2 more PoCs

My opinion is that the config approach is slightly cleaner architecturally, as the account configuration is already being passed around to all the places it is needed.

smkent added a commit that referenced this issue Feb 20, 2023
Applied updates from upstream project template commits:

smkent/cookie-python@c6ad7e1...757202d

*   757202d Merge pull request #73 from smkent/poetry-1.3
|\
| * 056b551 Update project template pre-commit hooks versions
| * 279a2e4 Apply linting fix
| * 3336a1d Update pre-commit hooks
| * 647e372 Update dependencies
| * 8634e58 Regenerate poetry.lock
| * 444e81a Update Poetry version to 1.3
|/
* d839c1d Merge pull request #72 from smkent/updates
* 8be2dee Update pre-commit plugins
* 02be331 Update dependencies, unpin poetry-dynamic-versioning version

Updated project dependencies via `poetry update`:

Package operations: 0 installs, 36 updates, 0 removals

- Updating markupsafe (2.1.1 -> 2.1.2)
- Updating charset-normalizer (2.1.1 -> 3.0.1)
- Updating packaging (22.0 -> 23.0)
- Updating urllib3 (1.26.13 -> 1.26.14)
- Updating attrs (22.1.0 -> 22.2.0)
- Updating exceptiongroup (1.0.4 -> 1.1.0)
- Updating iniconfig (1.1.1 -> 2.0.0)
- Updating filelock (3.8.2 -> 3.9.0)
- Updating mypy-extensions (0.4.3 -> 1.0.0)
- Updating pbr (5.11.0 -> 5.11.1)
- Updating platformdirs (2.6.0 -> 3.0.0)
- Updating python-slugify (7.0.0 -> 8.0.0)
- Updating requests (2.28.1 -> 2.28.2)
- Updating setuptools (65.6.3 -> 67.3.2)
- Updating typing-extensions (4.4.0 -> 4.5.0)
- Updating coverage (6.5.0 -> 7.1.0)
- Updating gitpython (3.1.29 -> 3.1.31)
- Updating identify (2.5.9 -> 2.5.18)
- Updating pathspec (0.10.3 -> 0.11.0)
- Updating pytest (7.2.0 -> 7.2.1)
- Updating stevedore (4.1.1 -> 5.0.0)
- Updating typer (0.6.1 -> 0.7.0)
- Updating termcolor (2.1.1 -> 2.2.0)
- Updating types-toml (0.10.8.1 -> 0.10.8.4)
- Updating types-urllib3 (1.26.25.4 -> 1.26.25.6)
- Updating virtualenv (20.17.1 -> 20.19.0)
- Updating black (22.12.0 -> 23.1.0)
- Updating cruft (2.11.1 -> 2.12.0)
- Updating flake8-bugbear (22.12.6 -> 23.2.13)
- Updating isort (5.10.1 -> 5.12.0)
- Updating mypy (0.991 -> 1.0.1)
- Updating pep8-naming (0.13.2 -> 0.13.3)
- Updating poethepoet (0.16.5 -> 0.18.1)
- Updating pre-commit (2.20.0 -> 3.0.4)
- Updating pytest-github-actions-annotate-failures (0.1.7 -> 0.1.8)
- Updating types-requests (2.28.11.5 -> 2.28.11.13)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants