Beispiel #1
0
def extract_an_url(fname):
    """ Extracts from a filename the list

        The file is re-written without the extracted URL.

        fname -- The filename from which to extract the values.
    """
    urls = cache_object( fname + '.send' )

    url = None
    while ((url is None) and (len(urls) > 0)):
        url = urls.pop_random()
        if (not valid_image(url)):
            url = None

    if (url is None):
        return

    if (_g_dry_run):
        return url
    urls_sent = cache_object( fname + '.sent' )
    urls_sent.add( url )

    urls.save()
    urls_sent.save()

    return (url)
def _update_sources( sources ):

    for key, slist in sources.items():
        for s in slist:
            cache_to_compare = cache_object( s )
            module = __import__('scrapers.' + s, fromlist = [ 'get_urls', 'requires_moderation' ])
            if (module.requires_moderation()):
                cache_to_update = cache_object( key + '.moderate' )
            else:
                cache_to_update = cache_object( key + '.send' )

            module.update_urls( cache_to_compare, cache_to_update )

            cache_to_compare.save()
            cache_to_update.save()
Beispiel #3
0
def main():

    qotds = get_qotds()

    # Read config file
    config = ConfigParser.RawConfigParser(allow_no_value=True)
    config.readfp( open( os.path.join( APP_DIR, 'app.settings' ) ) )

    # Login credentials
    email_addr = config.get( 'mail', 'address' )
    email_pass = config.get( 'mail', 'password' )
    # Default destination email
    default_dst_addr = config.get ( 'mail', 'destination' )

    # Build reverse maps for names to group names
    names_map = _build_group_reverse_map( config, 'names' )

    # Get the names into a list and shuffle them
    names = list(names_map.keys())
    random.shuffle( names )

    # Get a list of random IDs and the ones we've sent (and cached)
    bash_cache = cache_object( 'bash', sep = ',' )
    bash_data  = (bash.get_randoms( bash_cache ), bash_cache)

    server = None if _g_dry_run else email1.get_server(email_addr, email_pass)

    for name in names:

        to_addrs, bcc_addrs = _get_to_addrs(config, name, default_dst_addr)
        if (len(to_addrs) == 0):
            continue

        url = extract_an_url( names_map[name] )

        if (url is None):
            log.warning("No image URL for '%s'", name)

        _send_neatza( server, email_addr, name, qotds, bash_data, url, to_addrs, bcc_addrs )

    bash_cache.save()
    if (not _g_dry_run):
        server.quit()