def run(options): """ executes the purpose of this program having options into account """ courseid = str(options.courseid) themeid = str(options.themeid) exercises = [] for path in options.files: if not path.endswith(".html"): print "WARNING: unsuported format %s (ignored)"%path continue if not os.path.isfile(path): print "WARNING: file not found %s (ignored)"%path continue with open(path) as f: soup = BeautifulSoup(f.read()) title = unicode(soup.title.text).strip().encode("utf-8") description = "\n".join(str(c).strip() for c in soup.body.div.contents if not c == None and len(str(c).strip())> 0 and not c.name == "h1") exercise = MoodleExercise(title, description) if options.duedate: exercise.set_allowsubmissionsfromdate(options.fromdate) exercise.set_duedate(options.duedate) exercises.append(exercise) if len(exercises)>0: moodle = MoodleScrapper() moodle.submit_exercises_on_theme(courseid, themeid, exercises) moodle.disconnect()
# set adding a new task control = moodle.br.form.find_control("jump") control.items[19].selected = True moodle.submit_selected_form() moodle.br.select_form(nr=0) print moodle.contents moodle.disconnect() sys.exit() #print "="*100, "\n", moodle.contents, "="*100, "\n" exercici = MoodleExercise("Exercici de prova avui", "Descripció de <b>prova</b>") exercici.set_allowsubmissionsfromdate("20/9/2016 14:55") exercici.add_file("try.py") moodle.submit_exercise(exercici) # desactiva l'edició moodle.follow_link("Desactiva edició") # Desconnexió moodle.disconnect() print "URL : ", moodle.response.geturl() # print "Body: ", response.read() #print "headers: ", moodle.response.info()
#! /src/bin/env python # encoding: utf-8 # Test MoodleExercise class from exercise import MoodleExercise exercise = MoodleExercise("un", "dos") exercise.set_allowsubmissionsfromdate("20/10/2016 14:55") exercise.set_duedate("21/11/2017 15:50") exercise.set_cutoffdate("19/9/2017 13:45") print exercise.data