Update import nethack logfile script
- Add a few roles to the ROLES mapping - Check if the logfile changed before writing it (avoid updating the timestamp if no changes were made)
This commit is contained in:
parent
d2ab14f649
commit
9e11021ae3
2 changed files with 122 additions and 484 deletions
|
@ -45,11 +45,14 @@ RACES = {
|
|||
}
|
||||
|
||||
ROLES = {
|
||||
'Arc': 'Archaeologist',
|
||||
'Kni': 'Knight',
|
||||
'Mon': 'Monk',
|
||||
'Pri': 'Priest',
|
||||
'Ran': 'Ranger',
|
||||
'Rog': 'Rogue',
|
||||
'Sam': 'Samurai',
|
||||
'Val': 'Valkyrie',
|
||||
}
|
||||
|
||||
GENDERS = {
|
||||
|
@ -64,7 +67,7 @@ ALIGNMENTS = {
|
|||
|
||||
def parse_args(argv, *a, **kw):
|
||||
parser = argparse.ArgumentParser(*a, **kw)
|
||||
parser.add_argument('-o', '--output',help='Path to the output file')
|
||||
parser.add_argument('-o', '--output', help='Path to the output file')
|
||||
parser.add_argument('logfile', help='Path to the Nethack log file to convert')
|
||||
args = parser.parse_args(argv)
|
||||
return args
|
||||
|
@ -133,15 +136,26 @@ def main(argv):
|
|||
'logfile': records,
|
||||
}
|
||||
|
||||
logfile_has_changed = False
|
||||
output_path = args.output
|
||||
output_file = None
|
||||
|
||||
if output_path and output_path != '-':
|
||||
output_file = open(output_path, 'w')
|
||||
with open(output_path, 'r') as existing_logfile:
|
||||
existing_logfile_object = json.load(existing_logfile)
|
||||
logfile_has_changed = existing_logfile_object.get('logfile', {}) != records
|
||||
|
||||
if logfile_has_changed:
|
||||
output_file = open(output_path, 'w')
|
||||
else:
|
||||
output_file = sys.stdout
|
||||
|
||||
json.dump(output_object, output_file, indent=2)
|
||||
output_file.write('\n')
|
||||
output_file.close()
|
||||
if output_file:
|
||||
json.dump(output_object, output_file, indent=2)
|
||||
output_file.write('\n')
|
||||
output_file.close()
|
||||
else:
|
||||
print('No changes to logfile')
|
||||
|
||||
return 0
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue