|
import httpx |
|
import tqdm |
|
|
|
|
|
session = httpx.Client() |
|
for year in range(2015, 2025): |
|
for month in range(1, 13): |
|
bz2 = f"https://ftp.acc.umu.se/mirror/wikimedia.org/other/pageview_complete/monthly/{year}/{year}-{str(month).zfill(2)}/pageviews-{year}{str(month).zfill(2)}-user.bz2" |
|
test = session.head(bz2) |
|
if test.status_code == 200: |
|
print(test, bz2) |
|
with session.stream("GET", bz2, follow_redirects=True) as stream, open( |
|
f"pageviews/pageviews-{year}{str(month).zfill(2)}-user.bz2", "wb" |
|
) as file, tqdm.tqdm(desc=f"{year}{str(month).zfill(2)}", unit="b",unit_scale=True) as pbar: |
|
if stream.status_code == 200: |
|
pbar.total = int(stream.headers.get("content-length")) |
|
for bytes_content in stream.iter_bytes(): |
|
file.write(bytes_content) |
|
pbar.update(len(bytes_content)) |
|
else: |
|
print(stream.status_code) |