I am trying to read from and write to a .adofai file (which from what I can tell is a modified .json which won't work with the json library) using strings.
This is the program I used for testing:
import re
with open("C:\Users\\user\Downloads\pythontime\mirror.adofai", "r") as f: #open and read from file, store data in s
print(f.read)
s = f.read()
s = re.sub("\"angleData\": \[0", "\"angleData\": [315", s) #replace 0 with 315
with open("C:\Users\\user\Downloads\pythontime\mirror.adofai", "w") as f: #open and write modified string to file
f.write(s)
mirror.adofai before modification:
{
"angleData": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"settings":
{
"version": 12 ,
"artist": "",
"specialArtistType": "None",
"artistPermission": "",
"song": "",
"author": "",
"separateCountdownTime": "Enabled",
"previewImage": "",
"previewIcon": "",
"previewIconColor": "003f52",
"previewSongStart": 0,
"previewSongDuration": 10,
"seizureWarning": "Disabled",
"levelDesc": "",
"levelTags": "",
"artistLinks": "",
"difficulty": 1,
"requiredMods": [],
"songFilename": "",
"bpm": 100,
"volume": 100,
"offset": 0,
"pitch": 100,
"hitsound": "Kick",
"hitsoundVolume": 100,
"countdownTicks": 4,
"trackColorType": "Single",
"trackColor": "debb7b",
"secondaryTrackColor": "ffffff",
"trackColorAnimDuration": 2,
"trackColorPulse": "None",
"trackPulseLength": 10,
"trackStyle": "Standard",
"trackGlowIntensity": 100,
"trackAnimation": "None",
"beatsAhead": 3,
"trackDisappearAnimation": "None",
"beatsBehind": 4,
"backgroundColor": "000000",
"showDefaultBGIfNoImage": "Enabled",
"bgImage": "",
"bgImageColor": "ffffff",
"parallax": [100, 100],
"bgDisplayMode": "FitToScreen",
"lockRot": "Disabled",
"loopBG": "Disabled",
"unscaledSize": 100,
"relativeTo": "Player",
"position": [0, 0],
"rotation": 0,
"zoom": 100,
"pulseOnFloor": "Enabled",
"startCamLowVFX": "Disabled",
"bgVideo": "",
"loopVideo": "Disabled",
"vidOffset": 0,
"floorIconOutlines": "Disabled",
"stickToFloors": "Enabled",
"planetEase": "Linear",
"planetEaseParts": 1,
"planetEasePartBehavior": "Mirror",
"customClass": "",
"legacyFlash": false ,
"legacyCamRelativeTo": false ,
"legacySpriteTiles": false
},
"actions":
[
],
"decorations":
[
]
}
The program is supposed to replace the first 0 in angleData
with a 315, but it gives the following error:
PS C:\Users\user> & C:/Users/user/AppData/Local/Programs/Python/Python39/python.exe c:/Users/user/Downloads/pythontime/mirror.py
File "c:\Users\user\Downloads\pythontime\mirror.py", line 2
with open("C:\Users\\user\Downloads\pythontime\mirror.adofai", "r") as f:
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
(Note that I've replaced my username with user
here for privacy reasons.)