-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.py
41 lines (33 loc) · 1.3 KB
/
session.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import requests
from bs4 import BeautifulSoup
import lxml
import configparser
#bring in config in global scope
config = configparser.ConfigParser()
config.read('config.ini')
#Gets the data from the site to cache
def getData(session):
print("Getting Data")
#Login and establish the session
response = session.post(config['PATHS']['LoginPost'], data=makeForm(session))
#dump worksheet view
response_cache = open("worksheet.html", "w")
response_cache.writelines(response.text)
response_cache.close()
#dump schedule view
path = config['PATHS']['WMTroot'] + "?Action=" + config['PATHS']['ScheduleView']
response = session.get(path)
sched_view = open("scheduleview.html", "w")
sched_view.writelines(response.text)
#helper function to setup the login form
def makeForm(session):
#get the login html so we can find hidden inputs to get around CSRF
login = session.get(config['PATHS']['LoginForm'])
soup = BeautifulSoup(login.text, "lxml")
hidden_inputs = soup.find_all("input", type="hidden")
form = {x["name"]: x["value"] for x in hidden_inputs}
form["hprLogin$adUserName"] = config['CREDS']['Username']
form["hprLogin$adPass"] = config['CREDS']['Password']
form["hprLogin$rdLoginType"] = "cn"
form["hprLogin$btnSubmit"] = "Login"
return form