tmp
This commit is contained in:
parent
366860a1ad
commit
22e19557d8
5 changed files with 162 additions and 7 deletions
32
spotifyJsonCleanUp.py
Normal file
32
spotifyJsonCleanUp.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import os
|
||||
import json
|
||||
|
||||
|
||||
def process_json_files(directory):
|
||||
for filename in os.listdir(directory):
|
||||
if filename.endswith('.json') and ("_mod.json" not in filename):
|
||||
filepath = os.path.join(directory, filename)
|
||||
|
||||
with open(filepath, 'r') as f:
|
||||
try:
|
||||
data = json.load(f)
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
|
||||
def remove_available_markets(obj):
|
||||
if isinstance(obj, dict):
|
||||
return {key: remove_available_markets(value) for key, value in obj.items() if key != 'available_markets'}
|
||||
elif isinstance(obj, list):
|
||||
return [remove_available_markets(item) for item in obj]
|
||||
else:
|
||||
return obj
|
||||
|
||||
modified_data = remove_available_markets(data)
|
||||
|
||||
modified_filepath = os.path.join(directory, f"{os.path.splitext(filename)[0]}_mod.json")
|
||||
with open(modified_filepath, 'w') as f:
|
||||
json.dump(modified_data, f, indent=4)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
process_json_files("prefetched")
|
||||
Loading…
Add table
Add a link
Reference in a new issue