def main():
    """Control block."""
    cfg.self_verify()
    directories.check_base_dir()
    db.init()
    
    save_choice = cfg.CURRENT_CHOICE
    
    for site_key in cfg.MULTIPLE_CHOICE:
        get_images_from_site(site_key)
        
    cfg.set_current_choice(save_choice)
    
    print "#"
    print "# total number of resized images: {cnt}".format(cnt=cnt_resized_images)
def main():
    """Control block."""
    cfg.self_verify()
    directories.check_base_dir()
    db.init()

    save_choice = cfg.CURRENT_CHOICE

    for site_key in cfg.MULTIPLE_CHOICE:
        get_images_from_site(site_key)

    cfg.set_current_choice(save_choice)

    print "#"
    print "# total number of resized images: {cnt}".format(
        cnt=cnt_resized_images)
def get_images_from_site(site_key):
    """Get images from a given site."""
    cfg.set_current_choice(site_key)
    directories.check_photo_dir()

    print header()

    all_image_urls = dispatch.get_images(cfg.get_current_site_record())

    fetched_image_urls = download_images(all_image_urls)

    good_image_urls = [x for x in fetched_image_urls if is_ok_for_wallpaper(x)]
    bad_image_urls = list(set(fetched_image_urls).difference(set(good_image_urls)))

    register_good_and_bad_image_urls_to_db(good_image_urls, bad_image_urls)
    delete_bad_images(bad_image_urls)

    if cfg.RESIZE_LARGE_IMAGES:
        resize_large_images(good_image_urls)
def main():
    """Control block."""
    cfg.self_verify()
    directories.check_base_dir()
    db.init()

    while  True:
        save_choice = cfg.CURRENT_CHOICE

        for site_key in cfg.MULTIPLE_CHOICE:
            get_images_from_site(site_key)

        cfg.set_current_choice(save_choice)

        print "#"
        print "# total number of resized images: {cnt}".format(cnt=cnt_resized_images)
        try:
            sleep(float(60*60*6)) #every 6 hours
        except KeyboardInterrupt:
            sys.exit()
def get_images_from_site(site_key):
    """Get images from a given site."""
    cfg.set_current_choice(site_key)
    directories.check_photo_dir()

    print header()

    all_image_urls = dispatch.get_images(cfg.get_current_site_record())
    # keep JPG files only:
    jpg_image_urls = [x for x in all_image_urls if x.lower().endswith('jpg')]

    fetched_image_urls = download_images(jpg_image_urls)

    good_image_urls = [x for x in fetched_image_urls if is_ok_for_wallpaper(x)]
    bad_image_urls = list(
        set(fetched_image_urls).difference(set(good_image_urls)))

    register_good_and_bad_image_urls_to_db(good_image_urls, bad_image_urls)
    delete_bad_images(bad_image_urls)

    if cfg.RESIZE_LARGE_IMAGES:
        resize_large_images(good_image_urls)