2020-01-19 15:25:00 +01:00
|
|
|
import time
|
|
|
|
import logging
|
|
|
|
from selenium import webdriver
|
|
|
|
from webdriverdownloader import ChromeDriverDownloader
|
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def _get_cookie_str(driver):
|
|
|
|
raw_cookies = driver.get_cookies()
|
|
|
|
baked_cookies = ''
|
|
|
|
for cookie in raw_cookies:
|
2020-01-20 00:39:28 +01:00
|
|
|
baked_cookies += cookie['name'] + "=" + {cookie['value'] + ";"
|
2020-01-19 15:25:00 +01:00
|
|
|
# Remove the trailing ;
|
|
|
|
return baked_cookies[:-1]
|
|
|
|
|
|
|
|
|
|
|
|
def generate_cookie(cookie_path):
|
|
|
|
gdd = ChromeDriverDownloader()
|
|
|
|
chrome_driver = gdd.download_and_install()
|
|
|
|
|
2020-01-19 15:40:41 +01:00
|
|
|
# TODO: load previous cookies so it does not ask to re verify using an
|
|
|
|
# email code each time
|
2020-01-19 15:25:00 +01:00
|
|
|
driver = webdriver.Chrome(executable_path=chrome_driver[1])
|
|
|
|
|
|
|
|
driver.get('https://www.humblebundle.com/login')
|
|
|
|
|
|
|
|
while '/login' in driver.current_url:
|
|
|
|
# Waiting for the user to login
|
|
|
|
time.sleep(.25)
|
|
|
|
|
|
|
|
cookie_str = _get_cookie_str(driver)
|
|
|
|
with open(cookie_path, 'w') as f:
|
|
|
|
f.write(cookie_str)
|
|
|
|
|
2020-01-20 00:39:28 +01:00
|
|
|
logger.info("Saved cookies to " + cookie_path)
|
2020-01-19 15:25:00 +01:00
|
|
|
|
|
|
|
driver.quit()
|