-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanage_whales.py
More file actions
214 lines (169 loc) · 6.76 KB
/
manage_whales.py
File metadata and controls
214 lines (169 loc) · 6.76 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/env python3
"""
Whale Database Management Tool
CLI tool for managing whale addresses in the database
"""
import sys
import json
sys.path.insert(0, '.')
from src.data.whale_repository import whale_repository
def add_whale(address: str, label: str, entity_type: str = "Unknown", category: str = "Unknown"):
"""Add a single whale address to the database"""
if not whale_repository:
print("❌ Database not available")
return False
try:
success = whale_repository.save_whale(
address=address,
label=label,
balance_eth=0.0, # Will be updated by scanner
entity_type=entity_type,
category=category
)
if success:
print(f"✅ Added whale: {label} ({address})")
else:
print(f"⚠️ Whale may already exist: {address}")
return success
except Exception as e:
print(f"❌ Error adding whale: {e}")
return False
def list_whales():
"""List all whales in the database"""
if not whale_repository:
print("❌ Database not available")
return
try:
whales = whale_repository.get_top_whales(limit=1000)
print(f"\n🐋 Total whales in database: {len(whales)}")
print("-" * 80)
for whale in whales:
balance = whale.get('balance_eth', 0)
print(f"• {whale['label']:<40} {whale['address'][:10]}... {balance:>15,.2f} ETH")
except Exception as e:
print(f"❌ Error listing whales: {e}")
def import_from_json(filename: str):
"""Import whale addresses from a JSON file"""
if not whale_repository:
print("❌ Database not available")
return False
try:
with open(filename, 'r') as f:
whales_data = json.load(f)
print(f"📄 Importing {len(whales_data)} whales from {filename}...")
successful = 0
failed = 0
for whale in whales_data:
try:
success = whale_repository.save_whale(
address=whale.get("address"),
label=whale.get("label", "Unknown"),
balance_eth=0.0,
entity_type=whale.get("entity_type", "Unknown"),
category=whale.get("category", "Unknown")
)
if success:
successful += 1
print(f"✅ Added: {whale.get('label')}")
else:
failed += 1
except Exception as e:
failed += 1
print(f"❌ Error: {e}")
print(f"\n📊 Import complete: {successful} added, {failed} failed/skipped")
return successful > 0
except Exception as e:
print(f"❌ Error importing from {filename}: {e}")
return False
def export_to_json(filename: str):
"""Export all whale addresses to a JSON file"""
if not whale_repository:
print("❌ Database not available")
return False
try:
whales = whale_repository.get_top_whales(limit=1000)
export_data = []
for whale in whales:
export_data.append({
"address": whale['address'],
"label": whale.get('label', ''),
"entity_type": whale.get('entity_type', 'Unknown'),
"category": whale.get('category', 'Unknown'),
"balance_eth": float(whale.get('balance_eth', 0))
})
with open(filename, 'w') as f:
json.dump(export_data, f, indent=2)
print(f"✅ Exported {len(export_data)} whales to {filename}")
return True
except Exception as e:
print(f"❌ Error exporting to {filename}: {e}")
return False
def remove_whale(address: str):
"""Remove a whale from the database"""
if not whale_repository:
print("❌ Database not available")
return False
try:
# Note: You'll need to add a delete method to whale_repository if not exists
print(f"⚠️ Delete functionality not yet implemented in repository")
print(f"Would remove whale: {address}")
return False
except Exception as e:
print(f"❌ Error removing whale: {e}")
return False
def get_stats():
"""Get database statistics"""
if not whale_repository:
print("❌ Database not available")
return
try:
stats = whale_repository.get_stats()
print("\n📊 Whale Database Statistics")
print("-" * 40)
print(f"Total whales: {stats.get('total_whales', 0)}")
print(f"Whales with ROI scores: {stats.get('whales_with_roi', 0)}")
print(f"Average ROI score: {stats.get('avg_roi_score', 0):.2f}")
except Exception as e:
print(f"❌ Error getting stats: {e}")
def main():
"""Main CLI function"""
import argparse
parser = argparse.ArgumentParser(description='Manage whale addresses in database')
subparsers = parser.add_subparsers(dest='command', help='Commands')
# Add whale command
add_parser = subparsers.add_parser('add', help='Add a whale address')
add_parser.add_argument('address', help='Ethereum address')
add_parser.add_argument('label', help='Whale label/name')
add_parser.add_argument('--type', default='Unknown', help='Entity type')
add_parser.add_argument('--category', default='Unknown', help='Category')
# List command
subparsers.add_parser('list', help='List all whales')
# Import command
import_parser = subparsers.add_parser('import', help='Import from JSON file')
import_parser.add_argument('file', help='JSON file path')
# Export command
export_parser = subparsers.add_parser('export', help='Export to JSON file')
export_parser.add_argument('file', help='JSON file path')
# Remove command
remove_parser = subparsers.add_parser('remove', help='Remove a whale')
remove_parser.add_argument('address', help='Ethereum address')
# Stats command
subparsers.add_parser('stats', help='Show database statistics')
args = parser.parse_args()
if not args.command:
parser.print_help()
return
if args.command == 'add':
add_whale(args.address, args.label, args.type, args.category)
elif args.command == 'list':
list_whales()
elif args.command == 'import':
import_from_json(args.file)
elif args.command == 'export':
export_to_json(args.file)
elif args.command == 'remove':
remove_whale(args.address)
elif args.command == 'stats':
get_stats()
if __name__ == "__main__":
main()