def test_list_days_of_month(self): year = 2014 month = 5 days = potd.list_days_of_month(year, month) self.assertEqual(len(days), 31) self.assertEqual('2014-05-01', days[0]) self.assertEqual('2014-05-31', days[-1])
def test_list_days_of_february(self): year = 2014 month = 2 days = potd.list_days_of_month(year, month) self.assertEqual(len(days), 28) self.assertEqual('2014-02-01', days[0]) self.assertEqual('2014-02-28', days[-1])
def save_month(year_month, verbose): year, month = [int(s) for s in year_month.split("-")] total_size = 0 img_count = 0 dates = potd.list_days_of_month(year, month) with futures.ThreadPoolExecutor(max_workers=100) as executor: downloads = dict((executor.submit(potd.save_one, date, verbose), date) for date in dates) for future in futures.as_completed(downloads): date = downloads[future] if future.exception() is not None: print("%r generated an exception: %s" % (date, future.exception())) else: img_size = future.result() total_size += img_size img_count += 1 print("%r OK: %r" % (date, img_size)) return img_count, total_size
def save_month(year_month, verbose): year, month = [int(s) for s in year_month.split('-')] total_size = 0 img_count = 0 dates = potd.list_days_of_month(year, month) with futures.ThreadPoolExecutor(max_workers=100) as executor: downloads = dict((executor.submit(potd.save_one, date, verbose), date) for date in dates) for future in futures.as_completed(downloads): date = downloads[future] if future.exception() is not None: print('%r generated an exception: %s' % (date, future.exception())) else: img_size = future.result() total_size += img_size img_count += 1 print('%r OK: %r' % (date, img_size)) return img_count, total_size