Skip to content

Commit

Permalink
Fix selector to new moodle layout
Browse files Browse the repository at this point in the history
change input type from file to interactive prompt
added assert
  • Loading branch information
niroyb committed Aug 28, 2013
1 parent 13d0bc6 commit dd2aa41
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions Scrap_Moodle.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
Dependencies :
lxml (pypi.python.org/pypi/lxml)
statedConnection and scraptools from https://github.com/niroyb/WebScraping
Requires a files named moodleCredentials.txt in the same folder as the script
it should contain only two lines : username on one and password on the other
'''

__author__ = "Nicolas Roy"
Expand All @@ -21,6 +19,7 @@
import re
from os.path import basename
from sys import stderr
import getpass

class MoodleConnect:
'''Moodle connection object with credentials'''
Expand Down Expand Up @@ -154,7 +153,7 @@ def __init__(self, moodleConnection):
pageSource = moodleConnection.main_page

# Find course boxes
elems = scraptools.getElementsFromHTML(pageSource, '.box.coursebox>h3>a')
elems = scraptools.getElementsFromHTML(pageSource, '.course_title a')

genieRe = '[A-Z]{1,4}-?([A-Z]{3})?'
numRe = '[0-9]{3,4}[A-Z]?'
Expand All @@ -175,13 +174,22 @@ def downloadDocuments(self):
course.saveResources()
print

def test_mypage(mypage):
assert len(myPage.coursePages) > 0, "Error no courses found"
#print '\n'.join([c.sigle for c in myPage.coursePages])
#print connection.main_page
#print '\n'.join([c.sigle for c in myPage.coursePages])

if __name__ == '__main__':

loginUrl = 'https://moodle.polymtl.ca/login/index.php'
username, password = open('moodleCredentials.txt').read().splitlines()
print 'Credentials', loginUrl
username = raw_input('username: ')
password = getpass.getpass('password: ')

#username, password = open('moodleCredentials.txt').read().splitlines()
print 'Establishing Connection...'
connection = MoodleConnect(loginUrl, username, password)

myPage = MoodleMyPage(connection)
test_mypage(myPage)
myPage.downloadDocuments()

0 comments on commit dd2aa41

Please sign in to comment.