def test_list_albums_new_site(self, mocked_get): """Should return a dictionary when parsing newer (after sep 2008) months""" expected = [ { "name": "Childhood Cancer Awareness Month", "url": "http://www.boston.com/bigpicture/2008/09/childhood_cancer_awareness_mon.html", }, { "name": "The Singapore Grand Prix", "url": "http://www.boston.com/bigpicture/2008/09/the_singapore_grand_prix.html", }, ] self.assertEqual(expected, list_albums(2008, 9))
def test_list_albums_old_site(self, mocked_get): """Should return a dictionary when parsing old (before sep 2008) months""" expected = [ { "name": "Uncontacted Tribe Photographed in Brazil", "url": "http://www.boston.com/bigpicture/2008/05/uncontacted_tribe_photographed.html", }, { "name": "Cassini Nears Four-year Mark", "url": "http://www.boston.com/bigpicture/2008/05/cassini_nears_fouryear_mark.html", }, ] self.assertEqual(expected, list_albums(2008, 8))
response = http.get(photo['url'], stream=True) except http.DownloadError: continue with open(file_path, 'wb') as f: shutil.copyfileobj(response.raw, f) if not file_path.endswith('.gif'): write_caption(file_path, photo['caption']) else: log.info(u'Photo album "{0}" already downloaded, skipping...'.format(name)) if __name__ == '__main__': print 'Big Picture Cataloguer v{0}'.format(VERSION) print 'Aengus Walton - http://ventolin.org' print '===========================' print '' parser = argparse.ArgumentParser() parser.add_argument( "directory", help="The directory in which photos are to be stored") args = parser.parse_args() if not os.path.exists(args.directory): log.info('{0} does not exist, creating...'.format(args.directory)) os.makedirs(args.directory) months = get_months(args.directory) for dt in months: albums = list_albums(dt.year, dt.month) for album in albums: album_path = os.path.join(sys.argv[-1], str(dt.year), '{0:02d}'.format(dt.month), album['name']) download_album(album['name'], album_path, album['url'])