File size: 975 Bytes
d93fd32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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)