-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautomod.py
More file actions
61 lines (55 loc) · 2.04 KB
/
automod.py
File metadata and controls
61 lines (55 loc) · 2.04 KB
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
52
53
54
55
56
57
58
59
60
page = "?vl[page]={}&mid=SubmissionsList"
skins = "https://gamebanana.com/skins/games/297"
sounds = "https://gamebanana.com/sounds/games/297"
sprays = "https://gamebanana.com/sprays/games/297"
effects = "https://gamebanana.com/effects/games/297"
count = 100
from tqdm import tqdm
import requests
from random import randint
from bs4 import BeautifulSoup
from pyunpack import Archive
cSkins = int(count*0.4)
cSounds = int(count*0.3)
cEffects = int(count*0.2)
count -= cSkins
count -= cSounds
count -= cEffects
cSprays = count
print("Downloading", cSkins, "Weapon Skins")
print("Downloading", cSounds, "Sounds")
print("Downloading", cEffects, "Effects")
print("Downloading", cSprays, "Sprays")
def downloadQuota(count, url):
quota = count
while quota > 0:
html = requests.get(url + page.format(randint(1,400))).text
soup = BeautifulSoup(html, "html.parser")
try:
for mod in soup.select("records > record"):
modPage = mod.select("a.Name")[0].get("href")
modPage = requests.get(modPage).text
soup = BeautifulSoup(modPage, "html.parser")
modFileName = soup.select("div.FileInfo > span > code")[0].string
modPage = soup.select(".SmallManualDownloadIcon")[0].parent.get("href")
modPage = requests.get(modPage).text
soup = BeautifulSoup(modPage, "html.parser")
download = soup.select(".SmallManualDownloadIcon")[0].parent.get("href")
print("downloading", modFileName, "with url", download)
filename = "./custom/TF2AutoMod/"+modFileName
# NOTE the stream=True parameter below
with requests.get(download, stream=True) as r:
r.raise_for_status()
with open(filename, 'wb') as f:
for chunk in tqdm(r.iter_content(chunk_size=1024), unit="KB", desc=filename):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
if modFileName.endswith(".zip") or modFileName.endswith(".rar"):
Archive(filename).extractall('../')
quota -= 1
except Exception as e:
print(e)
downloadQuota(cSkins, skins)
downloadQuota(cSounds, sounds)
downloadQuota(cEffects, effects)
downloadQuota(cSprays, sprays)