Created
May 10, 2025 14:28
-
-
Save MarkusMaal/1deaa580be1a2c0aa9bdecf261fb90f3 to your computer and use it in GitHub Desktop.
Map finder for NationsConverter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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