Esempio n. 1
0
def parse_module(module_url):
    module = web.storage(
        url=module_url,
        cached_xml="",
        screenshot="",
        title="",
        title_url="",
        directory_title="",
        description="",
        author="",
        author_email="",
        author_affiliation="",
        author_location="",
        render_inline="",
    )

    if not module_url.startswith("http://"):
        raise "Ooops! Submission has failed – the URL seems to be invalid."

    try:
        html = utils.dnl(module_url)
        html = web.htmlunquote(html)  # this may confuse the parser
        xml = utils.parse_xml(html)
    except:
        raise "Ooops! Submission has failed – the XML or HTML page could not be loaded successfully."

    xnodes = xml.xpath("//ModulePrefs")
    if not xnodes:
        raise "Ooops! The XML is valid, but we cannot find the module."
    xnodes = xnodes[0]

    for attr in module:
        module[attr] = xnodes.get(attr) or module[attr]

    return module
Esempio n. 2
0
def parse_module(module_url):
    module = web.storage(
        url=module_url, cached_xml='', screenshot='', title='', title_url='', 
        directory_title='', description='', author='', author_email='', 
        author_affiliation='', author_location='', render_inline='')
    
    if not module_url.startswith('http://'):
        raise 'Ooops! Submission has failed – the URL seems to be invalid.'
    
    try:
        html = utils.dnl(module_url)
        html = web.htmlunquote(html)  # this may confuse the parser
        xml = utils.parse_xml(html)
    except:
        raise 'Ooops! Submission has failed – the XML or HTML page could not be loaded successfully.'
    
    xnodes = xml.xpath('//ModulePrefs')
    if not xnodes:
        raise 'Ooops! The XML is valid, but we cannot find the module.'
    xnodes = xnodes[0]
    
    for attr in module:
        module[attr] = xnodes.get(attr) or module[attr]
    
    return module
Esempio n. 3
0
def grab_screenshot(screenshot_url):
    try:
        data = utils.dnl(screenshot_url)
        guid = utils.get_guid() + '.' + utils.get_extension_from_url(screenshot_url)
        image.save(data, 'public/img/screenshot/' + guid)
    
    except:
        raise 'Ooops! Submission has failed &#8211; <a href="%s">' % web.urlquote(screenshot) \
            + ' the screenshot</a> in your XML could not be found, was broken, or had the wrong dimensions' \
            + ' (should be above 30x20 and below 460x420).'
            
    return guid
Esempio n. 4
-1
def grab_screenshot(screenshot_url):
    try:
        data = utils.dnl(screenshot_url)
        guid = utils.get_guid() + "." + utils.get_extension_from_url(screenshot_url)
        image.save(data, "public/img/screenshot/" + guid)

    except:
        raise 'Ooops! Submission has failed &#8211; <a href="%s">' % web.urlquote(
            screenshot
        ) + " the screenshot</a> in your XML could not be found, was broken, or had the wrong dimensions" + " (should be above 30x20 and below 460x420)."

    return guid