You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
917 B
30 lines
917 B
from lxml.html import fromstring as lxml_from_string
|
|
from urllib.parse import urljoin
|
|
import requests
|
|
from panera_sync.saml_check import saml_check
|
|
from panera_sync.fill_form import get_form_fields
|
|
|
|
PANERA_URL = "https://pantry.panerabread.com"
|
|
|
|
|
|
def get_login_page(session: requests.Session):
|
|
landing = session.get(PANERA_URL)
|
|
return saml_check(session, landing)
|
|
|
|
|
|
def login_user(session, username, password):
|
|
response = get_login_page(session)
|
|
parsed = lxml_from_string(response.text)
|
|
form = parsed.xpath("//form")[0]
|
|
post_url, to_send = get_form_fields(form)
|
|
to_send["username"] = username
|
|
to_send["password"] = password
|
|
|
|
post_url = urljoin(response.url, post_url)
|
|
|
|
headers = {
|
|
"Host": "iso3.panerabread.com",
|
|
"Referer": "https://pantry.panerabread.com/",
|
|
}
|
|
r = session.post(post_url, data=to_send, headers=headers)
|
|
return saml_check(session, r)
|