Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: d8d95b8ad9
...
compare: 7decb72715
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 34 additions and 6 deletions.
  1. +5 −3 README
  2. +29 −3 mycourses.py
View
8 README
@@ -1,13 +1,15 @@
[Purpose]
-This python script will login to your MyCourses account and navigate its way through each course. When in a course, this script will dump all the news, course content and dropbox submissions to your output location. After running the script you should have a directory that represents each course which contains that course's content.
+This python script will login to your MyCourses account and navigate its way through each course. When in a course, this script will dump all the news, course content and dropbox submissions to your output location. After running the script you should have a directory that represents each course which will contain all of that course's content.
[Usage]
python mycourses.py -h
-python mycourses.py --output ~/mycourses_dump --crossdomain --news --content --dropbox --verbose 2 --delay 0
+python mycourses.py --output ~/mycourses_dump --crossdomain --news --content --dropbox --verbose 2 --delay 0 --zip
python mycourses.py --output ~/mycourses_dump --crossdomain --content --dropbox --verbose 1 --delay 0
+python mycourses.py --output ~/mycourses_dump --content --dropbox --zip
+python mycourses.py --output ~/mycourses_dump --content --dropbox
[Requirements]
-This script was developed on Ubuntu Server 10.10 with the following packages installed:
+This script was developed on Ubuntu Server 10.10 and 11.04 with the following packages installed:
libxml2-dev
libxslt1-dev
View
32 mycourses.py
@@ -19,6 +19,7 @@
import time
import re
import demjson
+import shutil
from pyquery import PyQuery as pq
from lxml import etree
from urlparse import urlparse
@@ -210,7 +211,7 @@ def get_course_link( self, course, content ):
return False
# download a single course
- def download_course( self, link, path ):
+ def download_course( self, link, path, title ):
course = self.get( link )
if course:
self.read_rpc_key( course )
@@ -220,6 +221,8 @@ def download_course( self, link, path ):
self.download_course_content( course, path )
if self.options.save_dropbox == True:
self.download_course_dropbox( course, path )
+ if self.options.zip_course == True:
+ self.zip_course( path, title )
return True
return False
@@ -349,17 +352,39 @@ def download_course_news( self, course, path ):
file.close()
continue
+ def zip_course( self, path, title ):
+ self.debug( 2, 0, "Zipping directory '" + path + "'" )
+ import zipfile
+ try:
+ import zlib
+ compression = zipfile.ZIP_DEFLATED
+ except:
+ compression = zipfile.ZIP_STORED
+ filename = re.sub(r'\.\.+', '.', path + ".zip" )
+ zip_file = zipfile.ZipFile( filename, "w" )
+ self.zip_directory( zip_file, compression, path, "" )
+ shutil.rmtree( path )
+
+ def zip_directory( self, zip_file, compression, directory, virtual_dir ):
+ for file in os.listdir( directory ):
+ full_path = os.path.join( directory, file )
+ if os.path.isfile( full_path ):
+ self.debug( 3, 0, "Adding file '" + os.path.join( virtual_dir, file ) + "' to zip" )
+ zip_file.write( full_path, os.path.join( virtual_dir, file ), compression )
+ elif os.path.isdir( full_path ):
+ self.zip_directory( zip_file, compression, full_path, os.path.join( virtual_dir, file ) )
+
# grab a list of courses and download each one of them
def download_courses( self ):
# for each course link returned after logging in
for index, link in enumerate( self.course_links ):
course_link = pq( link )
href = course_link.attr[ "href" ]
- title = self.clean_chars( course_link.text() )
+ title = re.sub(r'\s\s+', ' ', self.clean_chars( course_link.text() ) )
path = self.options.output
if os.path.exists( path + "/" + title ) == 0:
os.makedirs( path + "/" + title )
- if self.download_course( href, path + "/" + title ):
+ if self.download_course( href, path + "/" + title, title ):
self.debug( 0, 2, "Course '" + title + "' Successfully Saved!" )
else:
self.debug( 0, 0, "Course '" + title + "' Failed To Saved!" )
@@ -373,6 +398,7 @@ def download_courses( self ):
parser.add_option("-c", "--content", dest="save_content", help="save course content", action="store_true", default=False)
parser.add_option("-x", "--crossdomain", dest="crossdomain", help="save course content from outside of domain", action="store_true", default=False)
parser.add_option("-d", "--dropbox", dest="save_dropbox", help="save course dropbox", action="store_true", default=False)
+parser.add_option("-z", "--zip", dest="zip_course", help="zip each course directory", action="store_true", default=False)
(options, args) = parser.parse_args()
mycourses = MyCourses( "https://mycourses.rit.edu", options )

No commit comments for this range

Something went wrong with that request. Please try again.