/
downloader.py
103 lines (86 loc) · 2.95 KB
/
downloader.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python2
# Copyright 2013 -- Andrew Davies <andavies@cs.washington.edu>
#
# This is an automated grading script (codename "thunderfist").
#
# TODO(awdavies) Add in some more documentation!
import datetime
import getpass
import optparse
import re
import signal
import sys
import time
import urllib
import web_util as wu
# This will be where we log in.
WEBLOGIN_URL = "https://weblogin.washington.edu/"
# This is the url for the time schedule server (ASP... gross).
SCHEDULE_URL = "https://sdb.admin.washington.edu/timeschd/uwnetid/sln.asp"
# The cookie domains we're interested in. If these expire, they need to be
# reacquired (that rhymes!).
WEBLOGIN_REGEX = re.compile(r'weblogin.washington.edu', re.IGNORECASE)
CATALYST_URL = "https://catalyst.uw.edu/collectit/dropbox/summary/zahorjan/28608"
def sigint_handler(signal, frame):
print '\n\nSIGINT Caught. Exiting . . .'
sys.exit(0)
def parse_options():
def sln_callback(option, opt, value, parser):
setattr(parser.values, option.dest, value.split(','))
# Create instance of OptionParser Module, included in Standard Library
p = optparse.OptionParser(
description='Downloads homework for grading, and then auto-grades!',
prog='grader.py',
version='0.1a',
usage= '%prog [username] [pass]',
)
p.add_option('--user','-u', help='User name')
p.add_option(
'--password',
'-p',
help='Password. If ommitted, will be requested as user input.'
)
options, arguments = p.parse_args()
'''
if not options.user:
setattr(options, 'user', raw_input('[?] UW Netid: '))
if not options.password:
setattr(options, 'password', getpass.getpass('[?] Password: '))
'''
return options
p.print_help()
sys.exit(1)
def uw_netid_login(netid, password):
login_params = wu.parse_hidden_params(wu.send_get_request(WEBLOGIN_URL))
login_params['user'] = netid
login_params['pass'] = password
'''
TODO: Handle a) The WEBLOGIN_URL not opening, b) The username/pass being wrong
'''
wu.send_post_request(WEBLOGIN_URL, login_params)
def validate_login_cookie(cookie_jar, user, password):
'''
This determines if any of the necessary cookies are expired, and if so, we
will reacquire them.
'''
login = True
for cookie in cookie_jar:
if re.match(WEBLOGIN_REGEX, cookie.domain):
if not cookie.is_expired():
login = False
if login:
uw_netid_login(user, password)
def download_submissions(cookie_jar, user, password):
'''
This downloads and extracts the homework submissions.
TODO(awdavies) Implement me!
'''
def main():
# Set the cookie handler so we can pass around cookies
# for POST requests.
cookies = wu.set_url_opener()
opts = parse_options()
# download_submissions(cookies, opts.user, opts.password)
if __name__ == '__main__':
signal.signal(signal.SIGINT, sigint_handler)
main()