Skip to content

Instantly share code, notes, and snippets.

@fessehaye
Last active May 11, 2020 03:43
Show Gist options
  • Save fessehaye/37fdd65300556545d435e3363ababc38 to your computer and use it in GitHub Desktop.
Save fessehaye/37fdd65300556545d435e3363ababc38 to your computer and use it in GitHub Desktop.
Sort Slippi files by matchup played
import os,sys,shutil
from slippi import Game
from tqdm import tqdm
slippiDir = 'C:\\Users\\Simon\\Desktop\\FM-v5.9-Slippi-r18-Win\\Slippi\\'
target = 'C:\\Users\\Simon\\Desktop\\slippi\\'
def getChars(players):
chars = [player.character.name for player in players if player]
chars.sort()
return "vs".join(chars)
def sortToDir(slippiFiles):
try:
for file in tqdm(slippiFiles):
game = Game(file)
MUs = getChars(game.start.players)
if os.path.exists(target+MUs) is False:
os.mkdir(target+MUs)
shutil.copy(file, target+MUs)
else:
shutil.copy(file, target+MUs)
except IOError as e:
print("Unable to copy file. %s" % e)
except:
print("Unexpected error:", sys.exc_info())
try:
shutil.rmtree(target, ignore_errors=True)
os.mkdir(target)
slippiFiles = [slippiDir + f for f in os.listdir(slippiDir)]
print(str(len(os.listdir(slippiDir))) + " Replay Files in total")
print("Sorting Slippi Files for Matchups")
sortToDir(slippiFiles)
except:
print('Error while deleting directory')
@fessehaye
Copy link
Author

pip install tqdm
pip install py-slippi

@fessehaye
Copy link
Author

replace line 5-6 with the correct directories

@fessehaye
Copy link
Author

image
Result

@alevine
Copy link

alevine commented May 10, 2020

Hey, I tried this on windows with python 3.7.4 and I get this unhelpful error

25 Replay Files in total
Sorting Slippi Files for Matchups
 10%|████████████████                                                                                                                                                 | 1/10 [00:00<00:05,  1.59it/s]
Unexpected error: (<class 'KeyError'>, KeyError(85), <traceback object at 0x0000022687918F88>)

any idea what could do this?

@fessehaye
Copy link
Author

Hey just double checking that you replaced line 5-6 with the right directories?

It could potentially be that one of the slp files are corrupt or an older version? try using a few slp files and see if you get the same issue. Let me know if this works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment