Skip to content

Commit

Permalink
cleaning around
Browse files Browse the repository at this point in the history
  • Loading branch information
gcmalloc committed Sep 25, 2012
1 parent 34042a1 commit be4e98f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions bin/moodle
Expand Up @@ -4,15 +4,16 @@ import os
import sys
import codecs
import json
import getpass

CONF_FILE = ".moodle"

SELECT_ALL = 'a'
def init_moodle_directory(moodle):
print("Downloading a list of courses")
courses = list(moodle.get_courses())
print("Select the courses you want to download separated \
by a comma, '{}' for all.").format(SELECT_ALL)
print("Select the courses you want to download separated"
"by a comma, '{}' for all.").format(SELECT_ALL)
for index, course in enumerate(courses):
print(u"\t{})) {}".format(index, course.name))
valid = False
Expand Down Expand Up @@ -41,7 +42,8 @@ def course_download(moodle, url, directory=""):
os.mkdir(dir_name)
for document in documents:
moodle.fetch_document(document, dir_name)
def usage():

def print_usage():
print("Read The README")
exit(1)

Expand All @@ -56,20 +58,18 @@ print('''
#this overwrite the default codec used for stdout
streamWriter = codecs.lookup('utf-8')[-1]
sys.stdout = streamWriter(sys.stdout)
sys.stdout.encoding = 'utf-8'

if len(sys.argv) < 2 or len(sys.argv) > 3:
usage()
if len(sys.argv) < 2 or len(sys.argv) > 4:
print_usage()

print("Moodle handshake")
if len(sys.argv) == 2:
import getpass
passwd = getpass.getpass()
if not passwd:
print("You didn't provide any password")
exit(2)
sys.argv.append(passwd)
try:
print("Moodle handshake, please be patient.")
moodle = Moodle(sys.argv[1], sys.argv[2])
except (ConnexionIssue) as e:
print(u"Issue with authentication {}".format(str(e).strip()))
Expand Down
6 changes: 3 additions & 3 deletions epfl/moodle.py
Expand Up @@ -24,7 +24,7 @@ class Moodle(object):

CHUNCK = 1024 * 1024

def __init__(self, username, password, caching=True):
def __init__(self, username, password, caching=False):
"""This will create a new moodle handshake.
"""
self.login(username, password)
Expand Down Expand Up @@ -68,10 +68,10 @@ def get_courses(self):
yield Ressource(course_link.string, course_link['href'])

def get_documents(self, course):
print course.link
course_page = self.session.get(course.link)
soup = BeautifulSoup(course_page.text)
content = soup.find('div', 'course-content')

content = soup.find('div', {'class':'course-content'})
#Week separation
weeks = content.find('ul',recursive=False).findAll('li', recursive=False)
divisions = list()
Expand Down

0 comments on commit be4e98f

Please sign in to comment.