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()
# activa l'edició moodle.follow_link("Activa edició") # Troba tema per nom soup = moodle.contents # print soup # moodle.disconnect() # sys.exit() formid = "section%s"%temaid_escollit # selecciona el formulari del tema escollit if not moodle.select_form_by_id(formid): print "No s'ha trobat el formulari ", formid moodle.disconnect() sys.exit() # 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"