def get_modules(session): print("Getting modules...\n") modules = [] resp = session_get('{0}/courses/{1}/modules'.format(CANVAS_URL, COURSE_ID), session) tree = html.fromstring(resp.content) moduleNodes = tree.xpath( "//div[contains(@class, 'context_module') and contains(@class, 'item-group-condensed')]" ) # Last element is a blank module moduleNodes.pop() for moduleNode in moduleNodes: module = Module() module.name = moduleNode.attrib['aria-label'] print("Found Module ", module.name) module.items = get_items(moduleNode) modules.append(module) print("") return modules
def LmodModuleList(paths): # try: with open(WIKI_PAGE_LIST, "r") as f: wiki_url_list = json.loads(f.read()) # except: # print("Error loading the file %s." % WIKI_PAGE_LIST) # wiki_url_list = None import string moduleList = [] output = pexpect.run(MODULE_COMMAND + ' ' + string.join(paths, ':')) output_js = json.loads(output) if "jsonSoftwarePage" in MODULE_COMMAND: for elem in output_js: for v in elem["versions"]: name = v["full"] help = "-" prereq = "-" if v.has_key("help"): help = v["help"] if v.has_key("parent"): prereq = string.join(v["parent"], " or ").replace( "default:", "").replace("default", "").replace(":", " and ") newModule = Module(name, help, "-", prereq) if newModule.version[0] != ".": moduleList.append(newModule) elif "spider-json" in MODULE_COMMAND: # print(str(output_js)) cnt = 0 for module_name in output_js: data = output_js[module_name] for path in data: # print(" ",path) module_data = data[path] # print(str(module_data)) if module_data.has_key("fullName"): name = module_data["fullName"] help = "-" prereq = "-" type = "-" if module_data.has_key("whatis"): help = "\n".join(module_data["whatis"]) if module_data.has_key("parentAA"): prereq = string.join(module_data["parentAA"][0], " and ") if module_data.has_key( "propT") and module_data["propT"].has_key("type_"): type = module_data["propT"]["type_"].keys()[0] newModule = Module(name, help, "-", _prereq_list=[prereq], _type=type, wiki_url_list=wiki_url_list) newModule.name = module_name if newModule.version[0] != ".": found = False new_version = "" for n, m in enumerate(moduleList): if m.name == newModule.name: if newModule.version not in m.version: new_version = m.version + ", " + newModule.version else: new_version = m.version if len(m.help) > len(newModule.help): newModule = Module( name, m.help, "-", _prereq_list=(m.prereq_list + [prereq]), _type=type) else: newModule = Module( name, newModule.help, "-", _prereq_list=(m.prereq_list + [prereq]), _type=type) newModule.version = new_version newModule.name = module_name moduleList[n] = newModule found = True break if not found: moduleList.append(newModule) return moduleList