-
Notifications
You must be signed in to change notification settings - Fork 71
/
workshop.py
45 lines (39 loc) · 1.39 KB
/
workshop.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
import os
import re
import subprocess
import urllib.request
import keys
WORKSHOP = "steamapps/workshop/content/107410/"
USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36" # noqa: E501
def download(mods):
steamcmd = ["/steamcmd/steamcmd.sh"]
steamcmd.extend(["+force_install_dir", "/arma3"])
steamcmd.extend(["+login", os.environ["STEAM_USER"], os.environ["STEAM_PASSWORD"]])
for id in mods:
steamcmd.extend(["+workshop_download_item", "107410", id])
steamcmd.extend(["+quit"])
subprocess.call(steamcmd)
def preset(mod_file):
if mod_file.startswith("http"):
req = urllib.request.Request(
mod_file,
headers={"User-Agent": USER_AGENT},
)
remote = urllib.request.urlopen(req)
with open("preset.html", "wb") as f:
f.write(remote.read())
mod_file = "preset.html"
mods = []
moddirs = []
with open(mod_file) as f:
html = f.read()
regex = r"filedetails\/\?id=(\d+)\""
matches = re.finditer(regex, html, re.MULTILINE)
for _, match in enumerate(matches, start=1):
mods.append(match.group(1))
moddir = WORKSHOP + match.group(1)
moddirs.append(moddir)
download(mods)
for moddir in moddirs:
keys.copy(moddir)
return moddirs