-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession.py
51 lines (32 loc) · 1.52 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
42
43
44
45
46
47
48
49
50
51
import requests
from forms import *
ENDPOINT = 'https://print.ads.carleton.edu:9192'
APP = ENDPOINT + '/app'
UPLOAD = ENDPOINT + '/upload'
class Session(object):
def __init__(self):
self.session = requests.session()
def connect(self):
self.session.get(APP)
def login(self, username, password):
self.sesion.post(APP, data=mk_login(username, password))
def navigate(self):
self.session.get(APP + '?service=page/UserWebPrint', params=mk_web_print())
self.session.get(APP + '?service=action/1/UserWebPrint/0/$ActionLink')
def find_printer(self, printer):
query_base = '?service=direct/1/UserWebPrintSelectPrinter/table.tablePages.linkPage&sp=AUserWebPrintSelectPrinter%2Ftable.tableView&sp='
for page in range(1, 4):
resp0 = self.session.get(APP + query_base + page)
r = re.compile('value=\"([0-9]+)\" .*\n' + printer, re.MULTILINE | re.DOTALL)
match = r.search(resp0.text)
if match is not None:
return match.group(1)
raise Exception('Printer does not exist: ' + printer)
def select_printer(self, printer_id):
self.session.post(APP, data=mk_select_printer(printer_id))
def submit_options(self, copies):
resp = self.session.post(APP, data=mk_print_options(copies))
r = re.compile('uploadUID = \'([0-9]+)\'')
return r.search(resp.text).groups(1) # uid
def upload(self, uid, files):
self.session.post(UPLOAD + '/' + uid, data=files)