forked from 0LNetworkCommunity/scorpions-claw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
81 lines (61 loc) · 2.54 KB
/
main.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
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
import os
import typer
from GraphClient import Neo4jClient
from dotenv import load_dotenv
app = typer.Typer(help="A CLI tool for interacting with Neo4j and performing various tasks.")
class Neo4jCLI:
def __init__(self):
self.neo4j_client = None
def init_neo4j_connection(self):
"""Initialize the connection to the Neo4j database."""
load_dotenv()
uri = os.getenv("NEO4J_URI")
username = os.getenv("NEO4J_USERNAME")
password = os.getenv("NEO4J_PASSWORD")
if not uri or not username or not password:
typer.echo("Error: Missing required environment variables: NEO4J_URI, NEO4J_USERNAME, NEO4J_PASSWORD.")
raise typer.Exit(code=1)
self.neo4j_client = Neo4jClient(uri, username, password)
typer.echo(f"Connecting to Graph DB at {uri}...")
self.neo4j_client.connect()
typer.echo("...Connected!")
def disconnect(self):
"""Close the Neo4j connection."""
if self.neo4j_client:
self.neo4j_client.close()
typer.echo("Connection closed.")
self.neo4j_client = None
# Instantiate the CLI manager
cli_manager = Neo4jCLI()
cli_manager.init_neo4j_connection()
def sanity_command():
"""Test connection to Neo4j."""
typer.echo("Collecting all offending CWs")
sanity = cli_manager.neo4j_client.get_sanity()
typer.echo(f"Found {sanity} offending CWs")
def balance_command():
typer.echo("Exporting balance...")
balances = cli_manager.neo4j_client.get_balances()
typer.echo("Balance export completed.")
def root_sprayers_command():
typer.echo("Finding root sprayers...")
balances = cli_manager.neo4j_client.get_root_sprayers()
typer.echo("Root sprayers export completed.")
def spray_tree_command():
typer.echo("Finding spray tree for addr...")
balances = cli_manager.neo4j_client.get_spray_tree()
typer.echo("Spray tree export completed.")
def spray_tree_balances_command():
typer.echo("Finding spray tree for addr...")
test_acct = "0xbd6323842b5dc76e178ae7eaeacce7f"
balances = cli_manager.neo4j_client.get_spray_tree_with_balances(test_acct)
typer.echo("Spray tree balances export completed.")
# Explicitly register the commands without decorators
app.command("sanity")(sanity_command)
app.command("balance")(balance_command)
app.command("root-sprayers")(root_sprayers_command)
app.command("spray-tree")(spray_tree_command)
app.command("spray-tree-balances")(spray_tree_balances_command)
if __name__ == "__main__":
app()
cli_manager.disconnect()