Beispiel #1
0
def getStoreContext(url, contextid):
    """
    Retrieve the HTML contents of a resource and update :class:`.Context` 
    corresponding to ``contextid``.
    
    Parameters
    ----------
    url : str
        Location of resource.
        
    Returns
    -------
    context.id : int
        ID for the :class:`.Context`
    """

    try:
        response = urllib2.urlopen(url)
        response_content = response.read()

    except Exception as exc:    # Case not tested.
        try:
            getStoreContext.retry(exc=exc)
        except (IOError, HTTPError) as exc:
            logger.info((exc.code, exc.read()))        

    soup = BeautifulSoup(response_content)
    title = soup.title.getText()

    context = Context.objects.get(pk=contextid)
    context.content = soup.html()
    context.title = unidecode(title)
    context.retrieved = True
    context.save()
    
    return context.id
Beispiel #2
0
def getStoreContext(url, contextid):
    """
    Retrieve the HTML contents of a resource and update :class:`.Context` 
    corresponding to ``contextid``.
    
    Parameters
    ----------
    url : str
        Location of resource.
        
    Returns
    -------
    context.id : int
        ID for the :class:`.Context`
    """

    try:
        response = urllib2.urlopen(url)
        response_content = response.read()

    except Exception as exc:  # Case not tested.
        try:
            getStoreContext.retry(exc=exc)
        except (IOError, HTTPError) as exc:
            logger.info((exc.code, exc.read()))

    soup = BeautifulSoup(response_content)
    title = soup.title.getText()

    context = Context.objects.get(pk=contextid)
    context.content = soup.html()
    context.title = unidecode(title)
    context.retrieved = True
    context.save()

    return context.id