@@ -0,0 +1,1566 @@
+#!/usr/bin/env python -OO%0A# -*- coding: utf-8 -*-%0A%0Aimport itertools%0Aimport os%0Aimport urllib2%0Aimport time%0A%0Acurrent_working_directory = os.path.dirname(os.path.abspath(__file__))%0Aarchive_folder = os.path.join(current_working_directory, %22j-archive%22)%0ASECONDS_BETWEEN_REQUESTS = 5%0AERROR_MSG = %22ERROR: No game%22%0A%0Adef main():%0A%09create_archive_dir()%0A%09print %22Downloading game files%22%0A%09download_pages()%0A%0Adef create_archive_dir():%0A%09if not os.path.isdir(archive_folder):%0A%09%09print %22Making %25s%22 %25 archive_folder%0A%09%09os.mkdir(archive_folder)%0A%0Adef download_pages():%0A%09for page in itertools.count(1):%0A%09%09new_file_name = %22%25s.html%22 %25 page%0A%09%09destination_file_path = os.path.join(archive_folder, new_file_name)%0A%09%09if not os.path.exists(destination_file_path):%0A%09%09%09html = download_page(page)%0A%09%09%09if ERROR_MSG in html:%0A%09%09%09%09print %22Finished downloading. Now parse.%22%0A%09%09%09%09break%0A%09%09%09if html:%0A%09%09%09%09save_file(html, destination_file_path)%0A%09%09%09%09time.sleep(SECONDS_BETWEEN_REQUESTS) # Remember to be kind to the server%0A%09%09else:%0A%09%09%09print %22Already downloaded %25s%22 %25 destination_file_path%0A%0Adef download_page(page):%0A%09url = 'http://j-archive.com/showgame.php?game_id=%25s' %25 page%0A%09html = None%0A%09try:%0A%09%09response = urllib2.urlopen(url)%0A%09%09if response.code == 200:%0A%09%09%09print %22Downloading %25s%22 %25 url%0A%09%09%09html = response.read()%0A%09%09else:%0A%09%09%09print %22Invalid URL: %25s%22 %25 url%0A%09except urllib2.HTTPError:%0A%09%09print %22failed to open %25s%22 %25 url%0A%09return html%0A%0Adef save_file(html, filename):%0A%09try:%0A%09%09with open(filename, 'w') as f:%0A%09%09%09f.write(html)%0A%09except IOError:%0A%09%09print %22Couldn't write to file %25s%22 %25 filename%0A%0Aif __name__ == %22__main__%22:%0A%09main()%0A%09%0A

Create download.py