Exemplo n.º 1
0
    def show_course_discussion_forums(self, course_id, n=None):
        '''
        Show all discussion forums of a particular course
        Input:
            course_id (int) : ID of the course
            n (int) : show only top `n` discussion forums
        '''
        token, userid = utils.get_credential()
        payload = {
            'wstoken': token,
            'wsfunction': 'mod_forum_get_forums_by_courses',
            'courseids[0]': course_id
        }
        res = requests.post(
            'https://moodle.iitb.ac.in/webservice/rest/server.php?moodlewsrestformat=json',
            data=payload)
        table = []
        i = 1
        for x in json.loads(res.text):
            if n is not None and int(n) < i:
                break

            table.append([x['id'], x['name']])
            i += 1

        print(tabulate(table, headers=["Forum ID", "Forum Name"]))
Exemplo n.º 2
0
    def show_courses(self):
        '''
        Show details of all enrolled courses
        '''
        url = 'https://moodle.iitb.ac.in/webservice/rest/server.php?moodlewsrestformat=json'

        token, userid = utils.get_credential()

        payload = {
            'wstoken': token,
            'wsfunction': 'core_enrol_get_users_courses',
            'userid': userid
        }
        res = requests.post(url, data=payload)
        table = list()
        i = 1
        for x in json.loads(res.text):
            table.append(
                [i, x['id'], x['progress'], x['shortname'], x['fullname']])
            i += 1

        print(
            tabulate(table,
                     headers=[
                         'sl No', 'Course id', 'Progress', 'Short Name',
                         'Full Name'
                     ]))
Exemplo n.º 3
0
    def show_grades(self, course_id):
        '''
        Show grades of a course
        Input:
            course_id (int) : ID of the course
        '''
        token, userid = utils.get_credential()
        payload = {
            'wstoken': token,
            'wsfunction': 'gradereport_user_get_grade_items',
            'courseid': course_id,
            'userid': userid
        }
        res = requests.post(
            'https://moodle.iitb.ac.in/webservice/rest/server.php?moodlewsrestformat=json',
            data=payload)
        table = list()

        for x in json.loads(res.text)['usergrades']:
            i = 1
            for grades in x['gradeitems']:
                table.append([
                    i, grades['graderaw'], grades['grademax'],
                    grades['percentageformatted']
                ])
                i += 1
            break

        print(tabulate(table, headers=['sl No', 'Grade', 'Max', 'Percentage']))
Exemplo n.º 4
0
    def show_discussions_from_a_forum(self, forum_id, n=None):
        '''
        Show all discussions of a particular discussion forum
        Input:
            forum_id (int) : ID of the discussion forum
            n (int) : show only top `n` discussions
        '''
        token, userid = utils.get_credential()
        payload = {
            'wstoken': token,
            'wsfunction': 'mod_forum_get_forum_discussions',
            'forumid': forum_id
        }
        res = requests.post(
            'https://moodle.iitb.ac.in/webservice/rest/server.php?moodlewsrestformat=json',
            data=payload)
        print('Discussions:')
        i = 1
        for x in json.loads(res.text)['discussions']:
            if n is not None and int(n) < i:
                break

            print("\t", f"{i}.", datetime.fromtimestamp(x['created']),
                  x['name'])
            print('{}'.format(bs(x['message'], 'html.parser').get_text()),
                  end='\n\n')
            i += 1
Exemplo n.º 5
0
    def show_all_assignments(self):
        '''
        Show assignments of all courses
        '''
        token, userid = utils.get_credential()
        payload = {
            'wstoken': token,
            'wsfunction': 'mod_assign_get_assignments'
        }
        res = requests.post(
            'https://moodle.iitb.ac.in/webservice/rest/server.php?moodlewsrestformat=json',
            data=payload)

        table = list()

        for x in json.loads(res.text)['courses']:
            i = 1
            for assignment in x['assignments']:
                table.append([
                    i, x['shortname'], assignment['name'],
                    datetime.fromtimestamp(assignment['duedate'])
                ])
                i += 1

            table.append([])

        print(
            tabulate(
                table,
                headers=['sl No', 'Course Name', 'Assignment', 'Due Date']))
Exemplo n.º 6
0
 def show_all_quizzes(self):
     '''
     Show quizzes of all courses
     '''
     token, userid = utils.get_credential()
     payload = {'wstoken': token, 'wsfunction': 'mod_quiz_get_quizzes_by_courses'}
     
     res = requests.post('https://moodle.iitb.ac.in/webservice/rest/server.php?moodlewsrestformat=json',data=payload)
     i = 1
     table = list()
     
     for x in json.loads(res.text)['quizzes']:
         table.append([i, x['course'], x['id'], x['name'], x['grade'], datetime.fromtimestamp(x['timeopen']), datetime.fromtimestamp(x['timeclose'])])
         i += 1
         
     print(tabulate(table, headers = ['sl No', 'Course id', 'id', 'Name', 'Total Score', 'Quiz Opens', 'Quiz Closes']))
Exemplo n.º 7
0
    def show_course_announcements(self, course_id, n=None):
        '''
        Show course announcements of a particular course
        Input:
            course_id (int)
            n (int)
        '''
        token, userid = utils.get_credential()
        payload = {
            'wstoken': token,
            'wsfunction': 'mod_forum_get_forums_by_courses',
            'courseids[0]': course_id
        }

        res = requests.post(
            'https://moodle.iitb.ac.in/webservice/rest/server.php?moodlewsrestformat=json',
            data=payload)

        id = None
        for x in json.loads(res.text):
            if 'announce' in x['name'].lower():
                id = x['id']
                break

        if id is None:
            print("Course does not exist")
        else:
            payload = {
                'wstoken': token,
                'wsfunction': 'mod_forum_get_forum_discussions',
                'forumid': id
            }

            res = requests.post(
                'https://moodle.iitb.ac.in/webservice/rest/server.php?moodlewsrestformat=json',
                data=payload)
            print('Announcements:')
            i = 1
            for x in json.loads(res.text)['discussions']:
                if n is not None and int(n) < i:
                    break

                print("\t", f"{i}.", datetime.fromtimestamp(x['created']),
                      x['name'])
                print('{}'.format(bs(x['message'], 'html.parser').get_text()),
                      end='\n\n')
                i += 1
Exemplo n.º 8
0
    def show_assignments(self, course, show_only_due):
        '''
        Show assignments of a course
        Input:
            course (string) : filter for course name
            show_only_due (boolean) : when set to True, shows only due assignments
        '''
        course = course.lower()
        token, userid = utils.get_credential()
        payload = {
            'wstoken': token,
            'wsfunction': 'mod_assign_get_assignments'
        }

        res = requests.post(
            'https://moodle.iitb.ac.in/webservice/rest/server.php?moodlewsrestformat=json',
            data=payload)

        table = list()

        for x in json.loads(res.text)['courses']:
            i = 1
            if course in x['shortname'].lower(
            ) or course in x['fullname'].lower():
                for assignment in x['assignments']:
                    # assignment is not due
                    if show_only_due and datetime.fromtimestamp(
                            assignment['duedate']) < datetime.fromtimestamp(
                                time.time()):
                        continue

                    table.append([
                        i, x['shortname'], assignment['name'],
                        datetime.fromtimestamp(assignment['duedate'])
                    ])
                    i += 1
                table.append([])
                break

        print(
            tabulate(
                table,
                headers=['sl No', 'Course Name', 'Assignment', 'Due Date']))