-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
193 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
## 0.1.2 | ||
|
||
* (01) Removes `--email` and `--password` | ||
* (02) Supports downloading "references" of a course | ||
|
||
## 0.1.1 | ||
|
||
* Add `--cookies` | ||
* (01) Adds `--cookies` | ||
|
||
## 0.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
import os | ||
import zipfile | ||
import io | ||
import re | ||
import logging | ||
|
||
from .lib.ExploringTree import ExploringTree | ||
|
||
from .markup import render_supplement | ||
|
||
from .resource import load_resource | ||
from .define import URL_ROOT | ||
from .markup import CML | ||
|
||
|
||
def _shorten_slug(x): | ||
|
@@ -23,8 +26,7 @@ def __init__(self, *, soc, outdir): # "soc" means "sepc or course" | |
self._outdir = outdir | ||
|
||
self._et = ExploringTree() | ||
with self._et: | ||
self._resource_node = self._et.jump('%s/resource' % self._soc['slug']) | ||
self._resource_node = self._et.see('%s/resource' % self._soc['slug']) | ||
|
||
self._dl_tasks = [] | ||
self._file_tasks = [] | ||
|
@@ -81,9 +83,40 @@ def _gather_course(self, course, i=None): | |
with self._et: | ||
self._down(course['slug'], i) | ||
|
||
self._gather_course_references(course) | ||
|
||
for _i, module in enumerate(course['modules']): | ||
self._gather_module(module, _i) | ||
|
||
def _gather_course_references(self, course): | ||
with self._et: | ||
self._down('references') | ||
|
||
refid2node = {} | ||
for i, ref in enumerate(course['references']): | ||
item = ref['item'] | ||
if item['type'] == 'CML': | ||
refid2node[ref['id']] = self._et.see('%02d@%s.html' % (i + 1, ref['slug'])) | ||
|
||
def fn_a(a): | ||
_refid = a.get('refid') | ||
if not _refid: | ||
return | ||
|
||
_node = refid2node.get(_refid) | ||
if not _node: | ||
logging.warning('[fn_a] unknown _refid=%s\n%s' % | ||
(_refid, {_1: _2.abspath() for _1, _2 in refid2node.items()})) | ||
else: | ||
a['href'] = self._et.relpathTo(_node) | ||
|
||
self._fn_a = fn_a | ||
|
||
for i, ref in enumerate(course['references']): | ||
item = ref['item'] | ||
if item['type'] == 'CML': | ||
self._gather_cml(item, i, ref) | ||
|
||
def _gather_module(self, module, i): | ||
_shorten_slug(module) | ||
|
||
|
@@ -133,10 +166,17 @@ def _gather_supplement(self, supplement, i): | |
self._gather_cml(item, _i, supplement) | ||
|
||
def _gather_cml(self, cml, i, supplement): | ||
_data = render_supplement(content=cml['html'], | ||
resource_path=self._resource_path(), | ||
title='%s' % supplement['name']).encode('UTF-8') | ||
self._add_file_task(_data, self._see('%[email protected]' % (i + 1))) | ||
import bs4 | ||
html = cml['html'] | ||
html = bs4.BeautifulSoup(html, 'html.parser') | ||
for a in html.find_all('a'): | ||
self._fn_a(a) | ||
html = str(html) | ||
|
||
data = render_supplement(content=html, | ||
resource_path=self._resource_path(), | ||
title='%s' % supplement['name']).encode('UTF-8') | ||
self._add_file_task(data, self._see('%02d@%s.html' % (i + 1, supplement['slug']))) | ||
|
||
for asset in cml['assets']: | ||
self._gather_asset(asset) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.