ARTICLE AD BOX
I am trying to copy data from game files to my own files to mod said game, after some updates to the game I would need to rewrite one specific line on over a thousand files, however due to the mod files being modified, copy paste isn't viable. The files are almost-but-not-quite formatted like json files, where you get parent elements and child elements within brackets, but the formatting between each file isn't consistent. Each file has some variation of provinces={<provinces>} but it can include extra lines or whitespace varying file to file, some have provinces = {<provinces>} while others will have it over multiple lines.
Specifically, I need to copy what is within the brackets, which in most files is on the next line, but not always. I can modify the files that aren't consistent, but if the game gets another update and I need to do this again, the formatting may change again, and I would need to re-verify and re-modify each file.
I solved the issue by coming up with this
with open(<file>, "r") as file: contents = file.read() new = contents.split("provinces") contents = new[1] new = contents.split("{") contents = new[1] new = contents.split("}") contents = new[0]which does work, but I'm wondering if there is a more efficient way. This feels clunky.
to see the files I'm working with, if you're curious, all of the game files were uploaded here
https://paradox-api-lb7z.onrender.com/hoi4?view=txt&path=history%2Fstates%2F1-France.txt
