Ejemplo n.º 1
0
            try:
                for content in dic['contents']:
                    if str(content['type'])=='file':
                        print (str(index) + '.' + str(content['filename']) + ': ' + str(content['fileurl']) +
                        '\t Type: ' + str(content['type']))
                        files[str(index)] = [str(content['filename']), str(content['fileurl']).split('?')[0]]
                        index = index + 1
                    else:
                        print ('   ' + str(content['filename']) + ': ' + str(content['fileurl']) +
                        '\t Type: ' + str(content['type']))
            except KeyError:
                None
    return files
    
if __name__ == '__main__':
    t = MoodLib(info['web'], users['student']['token'])
    print 'Introduce the course ID to download files'
    courseid = raw_input()
    contents = t.get_contents(courseid) # get the contents form the selected course
    files = show_course_contents(contents) # show contents in console and save the downloadable files' names and URLs in an array
    print 'Input: file index'
    fileindex = raw_input()
    try:
        print 'Selected file: ' + files[fileindex][0]
        f = open(files[fileindex][0], 'w')
        url = files[fileindex][1] + '&token=' + t.get_token()
        print url
        response = urllib2.urlopen(url)
        f.write(response.read())
        f.close()
        print response.getcode()
Ejemplo n.º 2
0
'''
Created on 07/06/2013

@author: javi
'''
from MoodPyth.MoodLib import MoodLib

if __name__ == '__main__':
    url = 'http://adry3000.dyndns.org/'     # initializes constructor parameters
    token = 'f03f665848ef2a85e3aee8a1db198ac0'
    t = MoodLib(url, token)         # class constructor
    contents = t.get_contents(2)    # get contents form the course which identifier is 2
    for section in contents:        # go through course sections
        if 'modules' in section:
            for module in section['modules']:   # go through section modules
                if 'contents' in module:
                    for content in module['contents']:  # go through module contents
                        if str(content['type'])=='file':    # if the content is a file
                            print content['filename']       # its name is printed