示例#1
0
def fetch_users(session):
    url = ('https://bb.au.dk/webapps/blackboard/execute/userManager' +
           '?course_id=%s' % session.course_id)
    response, keys, rows = fetch_datatable(session, url)
    try:
        return parse_users(keys, rows)
    except ValueError as exn:
        raise blackboard.ParserError(exn.args[0], response)
示例#2
0
def get_visit_stats(session):
    url = ('https://bb.au.dk/webapps/blackboard/content/manageDashboard.jsp' +
           '?course_id=%s' % session.course_id +
           '&sortCol=LastLoginCol&sortDir=D')
    response, keys, rows = fetch_datatable(session, url)
    # for r in list(response.history) + [response]:
    #     print("%s %s" % (r.status_code, r.url))
    return parse_visit_stats(keys, rows)
示例#3
0
文件: emails.py 项目: Mortal/bbfetch
def fetch_users(session):
    url = ('https://bb.au.dk/webapps/blackboard/execute/userManager' +
           '?course_id=%s' % session.course_id)
    response, keys, rows = fetch_datatable(session, url)
    try:
        return parse_users(keys, rows)
    except ValueError as exn:
        raise blackboard.ParserError(exn.args[0], response)
示例#4
0
def fetch_groups(session):
    """
    Computes a mapping from usernames (au123) to dictionaries,
    each dictionary containing the first/last name, role and group
    memberships of the particular user.
    The 'groups' entry is a list of (name, group id) pairs.
    """
    def strip_prefix(s, prefix):
        if s.startswith(prefix):
            return s[len(prefix):]
        else:
            raise ValueError("%r does not start with %r" % (s, prefix))

    def extract(key, cell, d):
        if key == 'userorgroupname':
            return d.split()[-1]
        if key not in ('Grupper', 'Groups'):
            return d
        groups = cell.findall('.//h:a[@class="userGroupNameListItemRemove"]',
                              NS)
        res = []
        for g in groups:
            name = element_text_content(g)
            i = g.get('id')
            res.append((name, strip_prefix(i, 'rmv_')))
        return res

    url = ('https://%s/webapps/bb-group-mgmt-LEARN/execute/' % DOMAIN +
           'groupInventoryList?course_id=%s' % session.course_id +
           '&toggleType=users&chkAllRoles=on')

    response, keys, rows = fetch_datatable(session,
                                           url,
                                           extract=extract,
                                           table_id='userGroupList_datatable',
                                           edit_mode=True)
    username = keys.index('userorgroupname')
    first_name = keys.index('firstname')
    last_name = keys.index('lastname')
    try:
        role = keys.index('Role')
    except ValueError:
        role = keys.index('Rolle')
    try:
        groups = keys.index('Groups')
    except ValueError:
        groups = keys.index('Grupper')
    users = {}
    for row in rows:
        users[row[username]] = dict(
            username=row[username],
            first_name=row[first_name],
            last_name=row[last_name],
            role=row[role],
            groups=row[groups],
        )
    return users
示例#5
0
def get_visit_stats(session):
    url = (
        'https://bb.au.dk/webapps/blackboard/content/manageDashboard.jsp' +
        '?course_id=%s' % session.course_id +
        '&sortCol=LastLoginCol&sortDir=D')
    response, keys, rows = fetch_datatable(session, url)
    # for r in list(response.history) + [response]:
    #     print("%s %s" % (r.status_code, r.url))
    return parse_visit_stats(keys, rows)
示例#6
0
文件: backend.py 项目: Mortal/bbfetch
def fetch_groups(session):
    """
    Computes a mapping from usernames (au123) to dictionaries,
    each dictionary containing the first/last name, role and group
    memberships of the particular user.
    The 'groups' entry is a list of (name, group id) pairs.
    """
    def strip_prefix(s, prefix):
        if s.startswith(prefix):
            return s[len(prefix):]
        else:
            raise ValueError("%r does not start with %r" % (s, prefix))

    def extract(key, cell, d):
        if key == 'userorgroupname':
            return d.split()[-1]
        if key not in ('Grupper', 'Groups'):
            return d
        groups = cell.findall(
            './/h:a[@class="userGroupNameListItemRemove"]', NS)
        res = []
        for g in groups:
            name = element_text_content(g)
            i = g.get('id')
            res.append((name, strip_prefix(i, 'rmv_')))
        return res

    url = ('https://bb.au.dk/webapps/bb-group-mgmt-LEARN/execute/' +
           'groupInventoryList?course_id=%s' % session.course_id +
           '&toggleType=users&chkAllRoles=on')

    response, keys, rows = fetch_datatable(
        session, url, extract=extract, table_id='userGroupList_datatable',
        edit_mode=True)
    username = keys.index('userorgroupname')
    first_name = keys.index('firstname')
    last_name = keys.index('lastname')
    try:
        role = keys.index('Role')
    except ValueError:
        role = keys.index('Rolle')
    try:
        groups = keys.index('Groups')
    except ValueError:
        groups = keys.index('Grupper')
    users = {}
    for row in rows:
        users[row[username]] = dict(
            username=row[username],
            first_name=row[first_name],
            last_name=row[last_name],
            role=row[role],
            groups=row[groups],
        )
    return users
示例#7
0
def get_all_users(session):
    url = (
        'https://blackboard.au.dk/webapps/blackboard/execute/userManager' +
        '?context=userPicker&course_id=_13158_1&enrollTypeString=UnEnrolled' +
        '&sortCol=userFirstName&sortDir=ASCENDING' +
        '&userInfoSearchKeyString=UserName' +
        '&userInfoSearchOperatorString=Contains&userInfoSearchText=a')
    response, keys, rows = fetch_datatable(session, url, 'get_all_users.csv')
    with open('all_users.html', 'wb') as fp:
        fp.write(url.encode('ascii') + b'\n')
        for r in list(response.history) + [response]:
            fp.write(('%s %s\n' % (r.status_code, r.url)).encode('ascii'))
        fp.write(response.content)
    return parse_all_users(keys, rows)
示例#8
0
def get_all_users(session):
    url = (
        'https://bb.au.dk/webapps/blackboard/execute/userManager' +
        '?context=userPicker&course_id=_13158_1&enrollTypeString=UnEnrolled' +
        '&sortCol=userFirstName&sortDir=ASCENDING' +
        '&userInfoSearchKeyString=UserName' +
        '&userInfoSearchOperatorString=Contains&userInfoSearchText=a')
    response, keys, rows = fetch_datatable(session, url, 'get_all_users.csv')
    with open('all_users.html', 'wb') as fp:
        fp.write(url.encode('ascii') + b'\n')
        for r in list(response.history) + [response]:
            fp.write(('%s %s\n' % (r.status_code, r.url)).encode('ascii'))
        fp.write(response.content)
    return parse_all_users(keys, rows)
示例#9
0
文件: forum.py 项目: johanbay/bbfetch
def get_forum_ids(session):
    def extract(key, cell, d):
        if key != 'title':
            return d
        link = cell.find('./h:span/h:a', NS)
        v = element_text_content(link)
        mo = re.search(r'conf_id=([^&]+)&forum_id=([^&]+)', link.get('href'))
        if not mo:
            raise ValueError("Could not match %s" % link.get('href'))
        return (mo.group(1), mo.group(2)), v

    url = ('https://bb.au.dk/webapps/discussionboard/do/conference' +
           '?action=list_forums&course_id=%s' % session.course_id +
           '&nav=discussion_board')
    response, keys, rows = fetch_datatable(session, url, extract=extract)
    title_col = keys.index('title')
    return [row[title_col] for row in rows]
示例#10
0
文件: forum.py 项目: kse/bbfetch
def get_forum_ids(session):
    def extract(key, cell, d):
        if key != 'title':
            return d
        link = cell.find('./h:span/h:a', NS)
        v = ' '.join(''.join(link.itertext()).split())
        mo = re.search(
            r'conf_id=([^&]+)&forum_id=([^&]+)', link.get('href'))
        if not mo:
            raise ValueError("Could not match %s" % link.get('href'))
        return (mo.group(1), mo.group(2)), v

    url = (
        'https://bb.au.dk/webapps/discussionboard/do/conference' +
        '?action=list_forums&course_id=%s' % session.course_id +
        '&nav=discussion_board')
    response, keys, rows = fetch_datatable(session, url, extract=extract)
    title_col = keys.index('title')
    return [row[title_col] for row in rows]