예제 #1
0
def main(today, lapse='month', testing=False, beta=False, local=False, local_file=None, github=True):
    """Main function"""
    
    # Check repository name consistency between CartoDB and GitHub
    checkNameConsistency.main()
    
    # Get API key, depending on whether or not it is in testing mode
    key = apikey(testing=testing)

    # (1) Extract downloads data: extractStats module
    if local is False:
        pubs = extractStats.main(today=today, lapse=lapse, testing=testing)
    else:
        logging.info("Loading from local file {0}".format(local_file))
        with open(local_file, 'rb') as inp_file:
            pubs = pickle.load(inp_file)

    # (2) Generate reports and models: generateReports module
    reports, models = generateReports.main(pubs=pubs, lapse=lapse, today=today)

    if github is True:

        # (3) Put reports and models in GitHub: uploadToGithub module
        git_urls = uploadToGithub.main(reports=reports, models=models, key=key, today=today, testing=testing, beta=beta)

        # (4) Create issues to notify users: addIssueToGithub module
        addIssueToGithub.main(git_urls=git_urls, key=key, today=today, testing=testing)

        return

    else:
        return reports
예제 #2
0
import monthlyStatReports

__author__ = '@jotegui'

today = datetime.now()

file_name = '/home/jotegui/VertNet/PublisherStats/pubs_{0}.pk'.format(format(today, '%Y_%m_%d'))

logging.basicConfig(filename='/home/jotegui/VertNet/PublisherStats/logs/with_local_{0}.log'.format(format(today, '%Y_%m_%d')),
                    format='%(levelname)s:%(asctime)s %(message)s', level=logging.DEBUG)

lapse = 'month'
testing = False
beta = False

pubs = extractStats.main(today=today, lapse=lapse, testing=testing)

# Piece of code to store pubs in disk (to avoid 1h+ of downloads)
logging.info('Writing to local file {0}'.format(file_name))
with open(file_name, 'wb') as output:
    pickle.dump(pubs, output, pickle.HIGHEST_PROTOCOL)

# After saving output, continue
monthlyStatReports.main(today=today, lapse=lapse, testing=testing, beta=beta, local=True, local_file=file_name)

end = datetime.now()
dif = end - today

logging.info('elapsed {0}'.format(dif))
logging.info('done')