Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8e15a0
commit ddf6318
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import csv | ||
import time | ||
from typing import List | ||
|
||
from google.protobuf.json_format import MessageToDict | ||
|
||
from node_launcher.node_set.lnd_client.rpc_pb2 import ChannelGraph | ||
from tools.channel_balancer import lnd_client | ||
|
||
|
||
def save_to_csv(name: str, data: List[dict]): | ||
timestamp = time.time() | ||
with open(f'{name}-{timestamp}.csv', 'w') as f: | ||
w = csv.DictWriter(f, data[0].keys()) | ||
w.writeheader() | ||
for d in data: | ||
w.writerow(d) | ||
|
||
|
||
def convert_to_dict(data): | ||
data = [MessageToDict(d) for d in data] | ||
return data | ||
|
||
|
||
def extract_data(): | ||
graph: ChannelGraph = lnd_client.get_graph() | ||
nodes = convert_to_dict(graph.nodes) | ||
edges = convert_to_dict(graph.edges) | ||
save_to_csv(name='nodes', data=nodes) | ||
save_to_csv(name='edges', data=edges) | ||
|
||
|
||
if __name__ == '__main__': | ||
extract_data() |