-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_test.py
More file actions
35 lines (27 loc) · 1020 Bytes
/
simple_test.py
File metadata and controls
35 lines (27 loc) · 1020 Bytes
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
28
29
30
31
32
33
34
35
import json
# Test the parsing logic
signals_str = "root={'RSI': 'Neutral', 'MACD': 'Sell', 'Overall': 'Sell'}"
print("Original:", signals_str)
# Parse the root= format
dict_str = signals_str[5:] # Remove "root=" prefix
dict_str = dict_str.replace("'", '"') # Convert single quotes to double quotes
dict_str = dict_str.replace('True', 'true').replace('False', 'false').replace('None', 'null')
print("Processed string:", dict_str)
try:
parsed = json.loads(dict_str)
print("Successfully parsed:", parsed)
print("Keys:", list(parsed.keys()))
# Normalize keys
normalized = {}
for key, value in parsed.items():
if key.upper() == 'RSI':
normalized['rsi'] = value
elif key.upper() == 'MACD':
normalized['macd'] = value
elif key.upper() == 'OVERALL':
normalized['overall'] = value
else:
normalized[key.lower()] = value
print("Normalized:", normalized)
except Exception as e:
print("Error:", e)