Skip to content

Instantly share code, notes, and snippets.

@apple1417
Created April 22, 2019 02:09
Show Gist options
  • Select an option

  • Save apple1417/c320994a101bc5970633d77f9ce48b04 to your computer and use it in GitHub Desktop.

Select an option

Save apple1417/c320994a101bc5970633d77f9ce48b04 to your computer and use it in GitHub Desktop.
import re
import os
import shutil
import zipfile
if not os.path.exists("tmp"):
os.makedirs("tmp")
all_gros = [f for f in os.listdir("Talos Workshop Backup") if f.endswith(".gro")]
all_levels = {}
for gro in all_gros:
shutil.copyfile("Talos Workshop Backup/" + gro, "tmp/" + gro[:-4] + ".zip")
try:
zip = zipfile.ZipFile("tmp/" + gro[:-4] + ".zip")
except zipfile.BadZipFile:
print("not a zip: " + gro)
continue
for info in zip.infolist():
if re.match(r'.*\.nfo$', info.filename, flags=re.I):
zip.extract(info, path="tmp/")
shutil.move("tmp/" + info.filename, "tmp/nfo.txt")
data = open("tmp/nfo.txt", "rb").read()
level = re.search(b"FIRSTLEVEL=['\"](.*?)['\"]", data, flags=re.I)
name = re.search(b"NAME=['\"](.*?)['\"]", data, flags=re.I)
if level != None:
if name == None:
name = "???"
all_levels[name.group(1).decode("utf-8").split("=")[-1]] = level.group(1).decode("utf-8")
print("")
for k in all_levels:
print(k + ": " + all_levels[k])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment