Skip to content

Instantly share code, notes, and snippets.

@MarkusMaal
Created May 10, 2025 14:28
Show Gist options
  • Select an option

  • Save MarkusMaal/1deaa580be1a2c0aa9bdecf261fb90f3 to your computer and use it in GitHub Desktop.

Select an option

Save MarkusMaal/1deaa580be1a2c0aa9bdecf261fb90f3 to your computer and use it in GitHub Desktop.
Map finder for NationsConverter
# requires pygbx from PyPI
from pygbx import Gbx, GbxType
import os, glob
def TrackInfo(path):
# add more authors to include
whitelisted_authors = ["Nadeo"]
# specify environments
# if you're using this script far into the future, you may need to add more envis here
whitelisted_envis = ["Stadium", "Speed", "Rally", "Alpine"]
# file does not exist
if not os.path.exists(path): return
# throw when gbx is invalid
try:
g = Gbx(path)
except:
return None
# filter to only challenge files
challenge = g.get_class_by_id(GbxType.CHALLENGE)
if not challenge:
return None
# remove these lines if you don't want to whitelist authors or environments
if not challenge.map_author in whitelisted_authors:
return None
if not challenge.environment in whitelisted_envis:
return None
# return path to map
return path
def Walk(path):
# accumulated maps
maps = []
print("Searching...")
for file in glob.glob(path, recursive=True):
if not TrackInfo(file) == None:
outstr = "Found map: " + file.replace(path.replace("**/*.*", ""), "")
print(outstr.ljust(os.get_terminal_size().columns - len(outstr) + 1) + "\r", end="")
maps += ["\"" + TrackInfo(file) + "\""]
print()
# make sure that NationsConverterCLI is in the same folder as Python script
# if you use Windows, change it to NationsConverterCLI.exe or something else
cmd = "./NationsConverterCLI " + " ".join(maps)
print("Running NationsConverter...")
# runs NationsConverter with all of the maps found passed as args
os.system(cmd)
if __name__ == "__main__":
# change this
Walk("/<path_to_tracks_challenges_folder>/**/*.*")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment