-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunique_market_extracter.py
27 lines (21 loc) · 1.04 KB
/
unique_market_extracter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os
import json
# ! This code iterated over the 'cryptoforce.json' file in the "coins" folder and updated the 'markets' key in each file to contain only unique values.
folder_path = "coins"
for filename in os.listdir(folder_path):
if filename.endswith(".json"):
file_path = os.path.join(folder_path, filename)
try:
with open(file_path, 'r') as f:
coin_data = json.load(f)
if "markets" in coin_data:
markets = coin_data["markets"]
unique_markets = list(set(markets))
coin_data["markets"] = unique_markets
with open(file_path, 'w') as fw:
json.dump(coin_data, fw, indent=4)
print(f"Successfully updated markets in {filename}")
else:
print(f"Warning: 'markets' key not found in {filename}")
except Exception as e:
print(f"Error processing {filename}: {e}")