Created
January 12, 2018 13:35
-
-
Save m-shibata/d39c1834f8cfe7987827e371358c0ac3 to your computer and use it in GitHub Desktop.
Download mailman archive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from datetime import date | |
import gzip | |
import shutil | |
import time | |
import urllib.request | |
import urllib.error | |
BASE_URL = 'http://lists.alioth.debian.org/pipermail/pkg-ime-devel/' | |
START_YEAR = 2004 | |
END_YEAR = 2018 | |
ARCHIVE = 'archive.mbox.gz' | |
def download(fname, fout): | |
url = '{base}{fname}'.format(base=BASE_URL, fname=fname) | |
try: | |
with urllib.request.urlopen(url) as res: | |
with gzip.GzipFile(fileobj=res) as gz: | |
shutil.copyfileobj(gz, fout) | |
except urllib.error.HTTPError as e: | |
print('Error: {code} for {fname}'.format(code=e.code, fname=fname)) | |
if __name__ == '__main__': | |
archive_list = b'' | |
try: | |
with urllib.request.urlopen(BASE_URL) as res: | |
archive_list = str(res.read()) | |
except urllib.error.HTTPError as e: | |
print('Error: {code} for {fname}'.format(code=e.code, fname=BASE_URL)) | |
with gzip.open(ARCHIVE, 'wb') as fout: | |
for y in range(START_YEAR, END_YEAR + 1): | |
for m in range(12): | |
fname = '{:%Y-%B}.txt.gz'.format(date(y, m + 1, 1)) | |
if fname in archive_list: | |
print('Downloading: {}'.format(fname)) | |
download(fname, fout) | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment