Created
May 1, 2016 17:38
-
-
Save vemacs/4ad2b7e0e29695b52b0e432bc4647882 to your computer and use it in GitHub Desktop.
This file contains 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
import os, yaml | |
datadir = 'userdata' | |
key = 'money' | |
maxbal = 2500.0 | |
def is_non_zero_file(fpath): | |
return True if os.path.isfile(fpath) and os.path.getsize(fpath) > 0 else False | |
for f in os.listdir(datadir): | |
if str(f).endswith('.yml'): | |
filepath = os.path.join(datadir, f) | |
should_correct = False | |
with open(filepath, 'r') as stream: | |
if not is_non_zero_file(filepath): | |
continue | |
userfile = yaml.load(stream) | |
if key in userfile and float(userfile[key]) > maxbal: | |
should_correct = True | |
if should_correct: | |
with open(filepath, 'w') as stream: | |
print('Corrected ' + filepath + ' with balance ' + userfile[key]) | |
userfile[key] = '0.0' | |
stream.write(yaml.dump(userfile, default_flow_style=False)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment