restructure
This commit is contained in:
28
tests/test_bc.py
Normal file
28
tests/test_bc.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import requests
|
||||
import browser_cookie3
|
||||
|
||||
BASE = "https://giantfood.com"
|
||||
ACCOUNT_PAGE = f"{BASE}/account/history/invoice/in-store"
|
||||
|
||||
USER_ID = "369513017"
|
||||
LOYALTY = "440155630880"
|
||||
|
||||
cj = browser_cookie3.firefox(domain_name="giantfood.com")
|
||||
|
||||
s = requests.Session()
|
||||
s.cookies.update(cj)
|
||||
s.headers.update({
|
||||
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:148.0) Gecko/20100101 Firefox/148.0",
|
||||
"accept": "application/json, text/plain, */*",
|
||||
"accept-language": "en-US,en;q=0.9",
|
||||
"referer": ACCOUNT_PAGE,
|
||||
})
|
||||
|
||||
r = s.get(
|
||||
f"{BASE}/api/v6.0/user/{USER_ID}/order/history",
|
||||
params={"filter": "instore", "loyaltyNumber": LOYALTY},
|
||||
timeout=30,
|
||||
)
|
||||
|
||||
print(r.status_code)
|
||||
print(r.text[:500])
|
||||
27
tests/test_bc_cffi.py
Normal file
27
tests/test_bc_cffi.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import browser_cookie3
|
||||
from curl_cffi import requests
|
||||
|
||||
BASE = "https://giantfood.com"
|
||||
ACCOUNT_PAGE = f"{BASE}/account/history/invoice/in-store"
|
||||
|
||||
USER_ID = "369513017"
|
||||
LOYALTY = "440155630880"
|
||||
|
||||
s = requests.Session()
|
||||
s.cookies.update(browser_cookie3.firefox(domain_name="giantfood.com"))
|
||||
s.headers.update({
|
||||
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:148.0) Gecko/20100101 Firefox/148.0",
|
||||
"accept": "application/json, text/plain, */*",
|
||||
"accept-language": "en-US,en;q=0.9",
|
||||
"referer": ACCOUNT_PAGE,
|
||||
})
|
||||
|
||||
r = s.get(
|
||||
f"{BASE}/api/v6.0/user/{USER_ID}/order/history",
|
||||
params={"filter": "instore", "loyaltyNumber": LOYALTY},
|
||||
impersonate="firefox",
|
||||
timeout=30,
|
||||
)
|
||||
|
||||
print(r.status_code)
|
||||
print(r.text[:500])
|
||||
66
tests/test_giant_login.py
Normal file
66
tests/test_giant_login.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import requests
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
BASE = "https://giantfood.com"
|
||||
ACCOUNT_PAGE = f"{BASE}/account/history/invoice/in-store"
|
||||
|
||||
USER_ID = "369513017"
|
||||
LOYALTY = "440155630880"
|
||||
|
||||
|
||||
def get_session():
|
||||
with sync_playwright() as p:
|
||||
browser = p.firefox.launch(headless=False)
|
||||
page = browser.new_page()
|
||||
|
||||
page.goto(ACCOUNT_PAGE)
|
||||
|
||||
print("log in manually in the browser, then press ENTER here")
|
||||
input()
|
||||
|
||||
cookies = page.context.cookies()
|
||||
ua = page.evaluate("() => navigator.userAgent")
|
||||
|
||||
browser.close()
|
||||
|
||||
s = requests.Session()
|
||||
|
||||
s.headers.update({
|
||||
"user-agent": ua,
|
||||
"accept": "application/json, text/plain, */*",
|
||||
"referer": ACCOUNT_PAGE,
|
||||
})
|
||||
|
||||
for c in cookies:
|
||||
domain = c.get("domain", "").lstrip(".") or "giantfood.com"
|
||||
s.cookies.set(c["name"], c["value"], domain=domain)
|
||||
|
||||
return s
|
||||
|
||||
|
||||
def test_history(session):
|
||||
url = f"{BASE}/api/v6.0/user/{USER_ID}/order/history"
|
||||
|
||||
r = session.get(
|
||||
url,
|
||||
params={
|
||||
"filter": "instore",
|
||||
"loyaltyNumber": LOYALTY,
|
||||
},
|
||||
)
|
||||
|
||||
print("status:", r.status_code)
|
||||
print()
|
||||
|
||||
data = r.json()
|
||||
|
||||
print("orders found:", len(data.get("records", [])))
|
||||
print()
|
||||
|
||||
for rec in data.get("records", [])[:5]:
|
||||
print(rec["orderId"], rec["orderDate"], rec["orderTotal"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
session = get_session()
|
||||
test_history(session)
|
||||
Reference in New Issue
Block a user