Example #1
0
def download_an_image(url, file_path, exclude_url=PARSER_EXCLUDE_URL):
    """
    :param url: image's url
    :param file_path: path to save image
    :return: {"200", "Zero", "Error", "link-anh-ko-hop-le", "Small",  exception_message}
    If url is in 'exclude_url' list : Stop downloading and return
    Get html content and write to file
    Check downloaded file's status and return it
    """
    if re.search("|".join(exclude_url), url) is not None:
        print "{0} : link anh ko hop le".format(url)
        return "link-anh-ko-hop-le"

    if SHOW_DOWNLOAD_STATUS:
        print "[{0}] {1} : Downloading".format(utils.get_current_time(), url)

    html_content = utils.urllib2_get(url=url)
    utils.write_string_to_file(file_path, html_content.read())

    if utils.get_file_size(file_path) == int(html_content.info()['Content-Length']):
        if utils.get_image_resolution(file_path) < 300:
            return "Small"
        else:
            return "200"
    elif utils.get_file_size(file_path) == 0:
        return "Zero"
    else:
        return "Error"
Example #2
0
 def get_file_stat(self):
     """
     :return: set image resolution and size for instances
     """
     self.file_size = utils.get_file_size(self.page_path)
     self.file_resolution = utils.get_image_resolution(self.page_path)