updaterooms.py 1.1 KB

12345678910111213141516171819202122
  1. import re, os
  2. print('This will update group and id of all the rooms in this directory.')
  3. group = int(input('Type the group number of the highest vanilla room: '))
  4. id = int(input('Type the id of the highest vanilla room: '))
  5. for directory, subdirectories, files in os.walk('.'):
  6. oldgroup = ''
  7. for file in files:
  8. if file.endswith('.json'):
  9. path = os.path.join(directory, file)
  10. temp = path[2:path.index('\\', 2)]
  11. id += 1
  12. if temp != oldgroup:
  13. group += 1
  14. oldgroup = temp
  15. print('Group id ' + str(group))
  16. print('Editing ' + path)
  17. with open(path, 'r' ) as f:
  18. content = f.read()
  19. content_new = re.sub(r'"group": ..', '"group": ' + str(group), content, flags = re.M)
  20. content_new = re.sub(r'"__separator_group_ID": ..', '"__separator_group_ID": ' + str(group), content_new, flags = re.M)
  21. content_new = re.sub(r'"__original_Index": ....', '"__original_Index": ' + str(id), content_new, flags = re.M)
  22. open(path, 'w').write(content_new)