def export_period(start, end = None):
    global action_manager, hash_generator
    """ It's best not to export current day """
    if not end:
        end = datetime.date.today() - datetime.timedelta(days=1)
    
    print "Please wait, this process - depending on popularity of your site may take some time."
    fetcher = GoogleFeedFetcher( config.GOOGLE_TABLE_ID )
    currentdate = start
    enddate = end
    
    action_manager = create_action_manager( fetcher, str(currentdate), str(enddate) )
    hash_generator = create_visit_hash_generator( fetcher, str(currentdate), str(enddate) )

    while currentdate <= enddate:
        VERBOSE("Exporting %s" % currentdate)
        if sql.nb_visits_day(currentdate, config.ID_SITE) == 0:
            export_day(str(currentdate), fetcher)
        else:
            VERBOSE("Export failed. Visit log for that day is not empty.")
        currentdate += datetime.timedelta(days=1)
        
    sql.update_visit_actions(start, end)
            
        print "Checking tables:",
        failed_tables = sql.check_tables(config.MYSQL_CREDENTIALS["table_prefix"])
        if len(failed_tables) == 0:
            print "[OK]"
        else:
            print "[FAILED]"
            print "Tables - %s doesn't exist." % ", ".join(failed_tables)

        print "Checking site:",
        try:
            sql.check_site(config.ID_SITE)
            print "[OK]"
        except:
            print "[FAILED], site with idsite = %s wasn't found" % config.ID_SITE
    else:
        config.read_config(options.config_file)
        if not (options.start_date or config.CONFIG_START):
            print "Start date parameter is required. For more info type ./google2piwik.py -h"
            exit()
        start_date = read_date(options.start_date or config.CONFIG_START)
        end_date = None if not (options.end_date or config.CONFIG_END) else read_date(options.end_date or config.CONFIG_END)
        sql.initialize(config.MYSQL_CREDENTIALS)
	if options.update_visit_actions:
	        sql.update_visit_actions(start_date, end_date)
		exit()

        sql.update_site_ts_created(config.ID_SITE, start_date)

        export_period(start_date, end_date)