def test_get_months_between_difference_months(self):
        date1 = datetime.datetime(2015, 7, 10).date()
        date2 = datetime.datetime(2015, 9, 15).date()
        
        months_between = data_science_jobs.get_months_between(date1, date2)

        expected_months_between = [datetime.datetime(2015, 8, 1).date()]
        self.assertEqual(months_between, expected_months_between)
Example #2
0
def update_monthly_summaries():
    logger.info('Update Monthly Summaries')
    previous_session = ScrapingSession.get_previous_session()
    logger.info('Previous Scraping Session: {}'.format(previous_session.datetime if previous_session else None))
    if previous_session == None:
        return
    last_summary = MonthlySummary.get_last_summary()
    logger.info('Last Monthly Summary: {}'.format(last_summary.date if last_summary else last_summary))
    if last_summary == None:
        start_date = JobListing.get_earliest_job_listing().added
        start_date = start_date - datetime.timedelta(days=start_date.day)
        start_date = datetime.datetime(year=start_date.year, month=start_date.month, day=1).date()
    else:
        start_date = last_summary.date
    previous_session_month = previous_session.datetime.date()
    previous_session_month = previous_session_month - datetime.timedelta(days=previous_session_month.day - 1)
    months_between = data_science_jobs.get_months_between(
        start_date,
        previous_session.datetime.date())
    logger.info('Months between: {}'.format(months_between))
    for date in months_between:
        monthly_summary = MonthlySummary.create(date=date)
        logger.info('{}: n_posts: {}'.format(date, monthly_summary.n_posts))
        monthly_summary.save()