Skip to content

Commit

Permalink
Merge pull request #14 from Woyken/main
Browse files Browse the repository at this point in the history
Some coupons are only found in V1 API
  • Loading branch information
Andre0512 authored Feb 8, 2024
2 parents 202cce4 + 4fe5aaa commit 30d479a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lidlplus/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@ def activate_coupons(args):
print("activating coupon: ", coupon["title"])
lidl_plus.activate_coupon(coupon["id"])
i += 1
# Some coupons are only available through V1 API
coupons = lidl_plus.coupon_promotions_v1()
for section in coupons.get("sections", {}):
for coupon in section.get("promotions", {}):
if coupon["isActivated"]:
continue
validity = coupon.get("validity", {})
if datetime.fromisoformat(validity["start"]) > datetime.now(timezone.utc):
continue
if datetime.fromisoformat(validity["end"]) < datetime.now(timezone.utc):
continue
print("activating coupon v1: ", coupon["title"])
lidl_plus.activate_coupon_promotion_v1(coupon["promotionId"])
i += 1
print(f"Activated {i} coupons")


Expand Down
14 changes: 14 additions & 0 deletions lidlplus/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Lidl Plus api
"""

import base64
import html
import logging
Expand Down Expand Up @@ -40,6 +41,7 @@ class LidlPlusApi:
_AUTH_API = "https://accounts.lidl.com"
_TICKET_API = "https://tickets.lidlplus.com/api/v2"
_COUPONS_API = "https://coupons.lidlplus.com/api"
_COUPONS_V1_API = "https://coupons.lidlplus.com/app/api/"
_PROFILE_API = "https://profile.lidlplus.com/profile/api"
_APP = "com.lidlplus.app"
_OS = "iOs"
Expand Down Expand Up @@ -269,6 +271,18 @@ def ticket(self, ticket_id):
url = f"{self._TICKET_API}/{self._country}/tickets"
return requests.get(f"{url}/{ticket_id}", **kwargs).json()

def coupon_promotions_v1(self):
"""Get list of all coupons API V1"""
url = f"{self._COUPONS_V1_API}/v1/promotionslist"
kwargs = {"headers": {**self._default_headers(), "Country": self._country}, "timeout": self._TIMEOUT}
return requests.get(url, **kwargs).json()

def activate_coupon_promotion_v1(self, promotion_id):
"""Activate single coupon by id API V1"""
url = f"{self._COUPONS_V1_API}/v1/promotions/{promotion_id}/activation"
kwargs = {"headers": {**self._default_headers(), "Country": self._country}, "timeout": self._TIMEOUT}
return requests.post(url, **kwargs)

def coupons(self):
"""Get list of all coupons"""
url = f"{self._COUPONS_API}/v2/{self._country}"
Expand Down

0 comments on commit 30d479a

Please sign in to comment.