-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathworkshop.py
More file actions
34 lines (31 loc) · 1.06 KB
/
workshop.py
File metadata and controls
34 lines (31 loc) · 1.06 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
import os
import re
import subprocess
import urllib.request
import shutil
import keys
import api
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 preset(mod_file, client):
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))
api.download_workshop(client, int(match.group(1)))
moddirs.append("workshop/" + match.group(1))
for moddir in moddirs:
keys.copy("server/"+moddir)
return moddirs