コード例 #1
0
def upload_assignments(host, username, password, program_string, source_csv):
    browser = login(host, username, password)

    url = 'https://%s/manage/%s/%s' % (
        host,
        program_string,
        'ajax_schedule_class',
        )

    if raw_input("Are you sure you want to load data to %s? (type yes) " % host).lower() != 'yes':
        print "You told me to stop."
        return

    section_assignments = collections.defaultdict(list)
    with open(source_csv, 'r') as source_file:
        reader = csv.reader(source_file)
        for row in reader:
            section_id, room_id, period_id = row
            section_assignments[section_id].append((period_id, room_id))

    if raw_input("About to schedule %s sections. Are you really sure? (type yes) " % len(section_assignments)).lower() != 'yes':
        print "You told me to stop."
        return

    for section_id, data in section_assignments.items():
        data.sort()
        post_data = urllib.urlencode({
                'cls': section_id,
                'action': 'assignreg',
                'block_room_assignments': '\n'.join('%s,%s' % block_room
                                                    for block_room in data),
            })

        # TEST THIS!
        browser.open(url, post_data)
コード例 #2
0
def upload_assignments(host, username, password, program_string, source_csv, old_csv, form_name):
    (browser, cookie_jar) = login(host, username, password, form_name)

    url = 'https://%s/manage/%s/%s' % (
        host,
        program_string,
        'ajax_schedule_class',
        )

    if raw_input("Are you sure you want to load data to %s? (type yes) " % host).lower() != 'yes':
        print "You told me to stop."
        return

    old_sections = set([])
    with open(old_csv, 'r') as old_file:
        reader = csv.reader(old_file)
        for row in reader:
            section_id, r, p = row
            old_sections.add(section_id)

    section_assignments = collections.defaultdict(list)
    with open(source_csv, 'r') as source_file:
        reader = csv.reader(source_file)
        for row in reader:
            section_id, room_id, period_id = row
            if not section_id in old_sections:
                section_assignments[section_id].append((period_id, room_id))

    if raw_input("About to schedule %s sections. Are you really sure? (type yes) " % len(section_assignments)).lower() != 'yes':
        print "You told me to stop."
        return

    num_scheduled = 0
    for section_id, data in section_assignments.items():
        data.sort()
        print  cookie_jar._cookies.values()[0]['/']['esp_csrftoken'].value
        post_data = urllib.urlencode({
                'csrfmiddlewaretoken': cookie_jar._cookies.values()[0]['/']['esp_csrftoken'].value,
                'cls': section_id,
                'action': 'assignreg',
                'block_room_assignments': '\n'.join('%s,%s' % block_room
                                                    for block_room in data),
            })

        # TEST THIS!
        # Set the referer to pass CSRF checks - <http://stackoverflow.com/a/13041112>
        browser.set_handle_referer(False)
        browser.set_handle_robots(False)
        browser.set_handle_refresh(True)
        browser.set_handle_redirect(True)
        browser.addheaders = [('Referer', 'https://' + host),]
        response = browser.open(url, post_data)
        print ' -- Scheduled section %s.  Response: %s' % (section_id, response.read())
        num_scheduled += 1
        if (num_scheduled % 100 == 0):
            print 'Scheduled %d sections so far.' % num_scheduled
        
        #print post_data
    print 'Scheduled %d sections successfully.' % num_scheduled
コード例 #3
0
def upload_assignments(host, username, password, program_string, source_csv, form_name):
    (browser, cookie_jar) = login(host, username, password, form_name)

    url = 'https://%s/manage/%s/%s' % (
        host,
        program_string,
        'ajax_schedule_class',
        )

    if raw_input("Are you sure you want to load data to %s? (type yes) " % host).lower() != 'yes':
        print "You told me to stop."
        return

    section_assignments = collections.defaultdict(list)
    with open(source_csv, 'r') as source_file:
        reader = csv.reader(source_file)
        for row in reader:
            section_id, room_id, period_id = row
            section_assignments[section_id].append((period_id, room_id))

    if raw_input("About to schedule %s sections. Are you really sure? (type yes) " % len(section_assignments)).lower() != 'yes':
        print "You told me to stop."
        return

    num_scheduled = 0
    for section_id, data in section_assignments.items():
        data.sort()
        print  cookie_jar._cookies.values()[0]['/']['esp_csrftoken'].value
        post_data = urllib.urlencode({
                'csrfmiddlewaretoken': cookie_jar._cookies.values()[0]['/']['esp_csrftoken'].value,
                'cls': section_id,
                'action': 'assignreg',
                'block_room_assignments': '\n'.join('%s,%s' % block_room
                                                    for block_room in data),
            })

        # TEST THIS!
        # Set the referer to pass CSRF checks - <http://stackoverflow.com/a/13041112>
        browser.set_handle_referer(False)
        browser.set_handle_robots(False)
        browser.set_handle_refresh(True)
        browser.set_handle_redirect(True)
        browser.addheaders = [('Referer', 'https://' + host),]
        response = browser.open(url, post_data)
        print ' -- Scheduled section %s.  Response: %s' % (section_id, response.read())
        num_scheduled += 1
        if (num_scheduled % 100 == 0):
            print 'Scheduled %d sections so far.' % num_scheduled
        
        #print post_data
    print 'Scheduled %d sections successfully.' % num_scheduled
コード例 #4
0
def upload_assignments(host, username, password, program_string, source_csv, form_name):
    (browser, cookie_jar) = login(host, username, password, form_name)

    url = "https://%s/manage/%s/%s" % (host, program_string, "ajax_schedule_class")

    if raw_input("Are you sure you want to load data to %s? (type yes) " % host).lower() != "yes":
        print "You told me to stop."
        return

    section_assignments = collections.defaultdict(list)
    with open(source_csv, "r") as source_file:
        reader = csv.reader(source_file)
        for row in reader:
            section_id, room_id, period_id = row
            section_assignments[section_id].append((period_id, room_id))

    if (
        raw_input("About to schedule %s sections. Are you really sure? (type yes) " % len(section_assignments)).lower()
        != "yes"
    ):
        print "You told me to stop."
        return

    num_scheduled = 0
    for section_id, data in section_assignments.items():
        data.sort()
        print cookie_jar._cookies.values()[0]["/"]["esp_csrftoken"].value
        post_data = urllib.urlencode(
            {
                "csrfmiddlewaretoken": cookie_jar._cookies.values()[0]["/"]["esp_csrftoken"].value,
                "cls": section_id,
                "action": "assignreg",
                "block_room_assignments": "\n".join("%s,%s" % block_room for block_room in data),
            }
        )

        # TEST THIS!
        # Set the referer to pass CSRF checks - <http://stackoverflow.com/a/13041112>
        browser.set_handle_referer(False)
        browser.set_handle_robots(False)
        browser.set_handle_refresh(True)
        browser.set_handle_redirect(True)
        browser.addheaders = [("Referer", "https://" + host)]
        response = browser.open(url, post_data)
        print " -- Scheduled section %s.  Response: %s" % (section_id, response.read())
        num_scheduled += 1
        if num_scheduled % 100 == 0:
            print "Scheduled %d sections so far." % num_scheduled

        # print post_data
    print "Scheduled %d sections successfully." % num_scheduled