-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdppb2_maps_downloader.py
51 lines (34 loc) · 1.17 KB
/
dppb2_maps_downloader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# A script to download all Digital Paint Paintball 2 maps, currently available on the server.
# It's a quick and dirty tool and you will have to do some more work on your own.
from bs4 import BeautifulSoup
import os
import requests
import shutil
def download_maps(url):
# The tool downloads all maps (.bsp)
# from a given url
html_webpage = requests.get(url).text
soup_webpage = BeautifulSoup(html_webpage)
files = soup_webpage.find_all("a")
if "beta" in url:
PATH = os.curdir + "/beta/"
os.mkdir(PATH)
else:
PATH = os.curdir
for file in files:
filename = file["href"]
if filename.endswith(".bsp"):
print(filename)
file_url = url + filename
response = requests.get(file_url, stream=True)
with open(PATH + filename, 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
def main():
url = "http://dplogin.com/files/maps/"
download_maps(url)
url = "http://dplogin.com/files/maps/beta/"
download_maps(url)
if __name__ == "__main__":
main()