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()
Example #3
0
# troba l'identificador de l'afegiment d'exercici (es podria deduir)
form = tema.find("form", attrs={"id":formid})
select = form.find("select", attrs={"name":"jump"})
for option in select.find_all("option"):
    if option.text.strip() == "Tasca":
        value = option["value"]
        break
else:
    print "No s'ha trobat l'opció pel formulari de creació de tasca"
    moodle.disconnect()
    sys.exit()

moodle.submit_form({"jump":[value]})
moodle.br.select_form(nr=0)
exercici = MoodleExercise("Exercici de prova avui", "Descripció de <b>prova</b>")
exercici.set_allowsubmissionsfromdate("20/9/2016 14:55")
exercici.set_duedate("21/10/2017 15:50")
exercici.set_cutoffdate("19/11/2017 13:45")
exercici.add_file("try.py")
moodle.submit_exercise(exercici)




# Desconnexió
moodle.disconnect()
print "URL    : ", moodle.response.geturl()
# print "Body: ", response.read()
#print "headers: ", moodle.response.info()
Example #4
0
#! /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

    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 "="*100, "\n", moodle.contents, "="*100, "\n"


exercici = MoodleExercise("Exercici de prova avui", """
    <h1>Descripció de la prova</h1>
    <p>Aquesta és la descripció de <b>prova</b></p>
    <p>Tinc fins i tot un diagrama a mostrar! <img
                          src="http://moiatgit.github.io/apuntstecnics/images/poo003.img001.ascensor.png"></p>
                          """
                          )
exercici.set_allowsubmissionsfromdate("20/10/2016 14:55")
moodle.submit_exercise(exercici)



# desactiva l'edició
moodle.follow_link("Desactiva edició")

# Desconnexió
moodle.disconnect()
print "URL    : ", moodle.response.geturl()
# print "Body: ", response.read()