Advertisement
InnovativeStudios

workshop.py

Jun 11th, 2023
930
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. import os
  2. import re
  3. import subprocess
  4. import requests
  5. import keys
  6.  
  7. WORKSHOP = "steamapps/workshop/content/107410/"
  8. 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
  9.  
  10.  
  11. def download(mods):
  12.     steamcmd = ["/steamcmd/steamcmd.sh"]
  13.     steamcmd.extend(
  14.         [
  15.             "+force_install_dir",
  16.             "/arma3",
  17.             "+login",
  18.             os.environ["STEAM_USERNAME"],
  19.             os.environ["STEAM_PASSWORD"],
  20.         ]
  21.     )
  22.     for id in mods:
  23.         steamcmd.extend(["+workshop_download_item", "107410", id])
  24.     steamcmd.extend(["+quit"])
  25.     subprocess.call(steamcmd)
  26.  
  27.  
  28. def preset(mod_file):
  29.     if mod_file.startswith("http"):
  30.         response = requests.get(mod_file, headers={"User-Agent": USER_AGENT})
  31.         with open("preset.html", "wb") as f:
  32.             f.write(response.content)
  33.         mod_file = "preset.html"
  34.  
  35.     mods = []
  36.     moddirs = []
  37.  
  38.     with open(mod_file) as f:
  39.         html = f.read()
  40.         regex = r"filedetails\/\?id=(\d+)\""
  41.         matches = re.finditer(regex, html, re.MULTILINE)
  42.  
  43.         for _, match in enumerate(matches, start=1):
  44.             mods.append(match.group(1))
  45.             moddir = WORKSHOP + match.group(1)
  46.             moddirs.append(moddir)
  47.  
  48.         download(mods)
  49.  
  50.         for moddir in moddirs:
  51.             keys.copy(moddir)
  52.  
  53.     return moddirs
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement