Skip to content

Instantly share code, notes, and snippets.

@luckylittle
Last active September 13, 2020 10:41
Show Gist options
  • Save luckylittle/3cca6e38d2178480820d450f3c1baf7e to your computer and use it in GitHub Desktop.
Save luckylittle/3cca6e38d2178480820d450f3c1baf7e to your computer and use it in GitHub Desktop.
Manning Publications - Creates folder structure based on the products in your dashboard
#!/bin/python3
"""
Author: Lucian Maly
"""
import requests
from bs4 import BeautifulSoup
import datetime
import os
import errno
import sys
loginURL = 'https://login.manning.com/login?service=https://www.manning.com/login/cas'
dashboardURL = 'https://www.manning.com/dashboard/index?filter=book&max=999&order=lastUpdated&sort=desc'
username = '[email protected]'
password = 'p4ss'
def create_folder():
global folder
datetime_object = datetime.date.today()
folder = str(datetime_object)
try:
os.mkdir(folder)
print('Created folder', folder)
except OSError as e:
if e.errno == errno.EEXIST:
print(f'Directory {folder} already exists.')
else:
raise
def get_list():
with requests.Session() as s:
soup1 = BeautifulSoup(s.get(loginURL).text, 'html.parser')
headers = {
'Origin': 'https://login.manning.com',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36'
}
data = {
'username': username,
'password': password,
'lt': soup1.find('input', {'name': 'lt'}).get('value'),
'execution': 'e1s1',
'_eventId': 'submit',
'submit': ''
}
s.post(loginURL, cookies=s.cookies, headers=headers, data=data)
dashboard = s.get(dashboardURL)
soup2 = BeautifulSoup(dashboard.text, 'html.parser')
for link in soup2.find_all('div', {'class': 'product-title'}):
subfolder = str(link.text.strip().replace(' ', '_'))
path = os.path.join(folder, subfolder)
os.makedirs(path)
def end_script():
print('Exiting the script...')
sys.exit()
create_folder()
get_list()
end_script()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment