Skip to content

Commit f75aae4

Browse files
committed
using .txt file for saving and fixing flake8
1 parent 3fe9e39 commit f75aae4

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

torbot/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def handle_tree_args(self, args):
7777

7878
# -d/--download
7979
if args.download:
80-
file_name = str(input("File Name (.pdf/.png/.svg): "))
80+
file_name = str(input("File Name (.txt): "))
8181
tree.save(file_name)
8282

8383
def perform_action(self):

torbot/modules/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ def get_log_level():
2222
if log_level_str == str_input:
2323
return log_level
2424

25+
2526
if not os.path.exists(data_directory):
2627
os.mkdir(data_directory)

torbot/modules/linktree.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,41 @@
11
"""
22
Module is used for analyzing link relationships
33
"""
4-
from treelib import Node, Tree, exceptions
4+
from treelib import Tree, exceptions
55

66
from .api import get_node
77
from .utils import join_local_path
8-
from .log import info, debug
8+
from .log import debug
9+
910

1011
def formatNode(n):
1112
return f"{n['url']} {n['status_code']} {n['status']}"
1213

14+
1315
def build_tree_recursive(t, n):
1416

17+
current_id = n["url"]
1518
# this will only be ran on the root node since others will exist before being passed
16-
if not t.contains(n["url"]):
17-
debug(f"adding root node {n}")
18-
t.create_node(formatNode(n), n["url"])
19+
if not t.contains(current_id):
20+
debug(f"adding id {current_id}")
21+
t.create_node(formatNode(n), current_id)
1922

23+
children = n["children"]
2024
# if there are no children, there's nothing to process
21-
if not n["children"]:
25+
if not children:
2226
return
2327

24-
for child in n["children"]:
25-
id = child["url"]
28+
for child in children:
29+
30+
current_id = child["url"]
2631
parent_id = n["url"]
32+
2733
try:
28-
debug(f"adding node {child}")
29-
debug(f"parent_id {parent_id}")
30-
t.create_node(formatNode(child), child["url"], parent=n["url"])
34+
debug(f"adding child_id {current_id} to parent_id {parent_id}")
35+
t.create_node(formatNode(child), current_id, parent=parent_id)
3136
except exceptions.DuplicatedNodeIdError:
32-
debug(f"found a duplicate url {child['url']}")
33-
continue # this node has already been processed somewhere else
37+
debug(f"found a duplicate url {current_id}")
38+
continue # this node has already been processed somewhere else
3439

3540
build_tree_recursive(t, child)
3641

@@ -53,21 +58,26 @@ def __build_tree(self, url: str, depth: int = 1):
5358
Returns:
5459
tree (ete3.Tree): Built tree.
5560
"""
56-
debug(f"building tree for {root} at {depth} depth")
61+
debug(f"building tree for {url} at {depth} depth")
5762
n = get_node(url, depth)
5863
t = Tree()
5964
build_tree_recursive(t, n)
60-
self._tree = t;
65+
self._tree = t
6166
debug("tree built successfully")
6267

6368
def save(self, file_name: str):
6469
"""
6570
Saves LinkTree to file with given file_name
66-
Current file types supported are .png, .pdf, .svg
71+
Current file types supported are .txt
6772
"""
6873
debug(f"saving link tree as {file_name}")
6974
file_path = join_local_path(file_name)
70-
self._tree.save2file(file_path)
75+
try:
76+
self._tree.save2file(file_path)
77+
except Exception as e:
78+
debug(f"failed to save link tree to {file_path}")
79+
raise e
80+
7181
debug(f"file saved successfully to {file_path}")
7282

7383
def show(self):

0 commit comments

Comments
 (0)