Skip to content

Commit c135a00

Browse files
committed
Adding logging
1 parent 583fb71 commit c135a00

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

torbot/modules/api.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import requests
77

88
from .utils import host, port
9+
from .log import info
910

1011
base_url: str = f'http://{host}:{port}'
1112

@@ -16,8 +17,11 @@ def get_node(link: str, depth: int):
1617
"""
1718
endpoint = f'/tree?link={link}&depth={depth}'
1819
url = base_url + endpoint
20+
info(f'requesting {url}')
1921
resp = requests.get(url)
20-
return resp.json()
22+
data = resp.json()
23+
info(f'retrieved {data}')
24+
return data
2125

2226

2327
def get_ip():
@@ -26,7 +30,9 @@ def get_ip():
2630
"""
2731
endpoint = '/ip'
2832
url = base_url + endpoint
33+
info(f'requesting {url}')
2934
resp = requests.get(url)
35+
info(f'retrieved {resp.text}')
3036
return resp.text
3137

3238

@@ -36,8 +42,11 @@ def get_emails(link: str):
3642
"""
3743
endpoint = f'/emails?link={link}'
3844
url = base_url + endpoint
45+
info(f'requesting {url}')
3946
resp = requests.get(url)
40-
return resp.json()
47+
data = resp.json()
48+
info(f'retrieved {data}')
49+
return data
4150

4251

4352
def get_phone(link: str):
@@ -46,8 +55,11 @@ def get_phone(link: str):
4655
"""
4756
endpoint = f'/phone?link={link}'
4857
url = base_url + endpoint
58+
info(f'requesting {url}')
4959
resp = requests.get(url)
50-
return resp.json()
60+
data = resp.json()
61+
info(f'retrieved {data}')
62+
return data
5163

5264

5365
def get_web_content(link: str):
@@ -56,5 +68,7 @@ def get_web_content(link: str):
5668
"""
5769
endpoint = f'/content?link={link}'
5870
url = base_url + endpoint
71+
info(f'requesting {url}')
5972
resp = requests.get(url)
73+
info(f'retrieved {resp.text}')
6074
return resp.text

torbot/modules/linktree.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
"""
22
Module is used for analyzing link relationships
33
"""
4+
45
from ete3 import Tree
56

67
from .api import get_node
78
from .utils import join_local_path
9+
from .log import info
810

911

1012
class LinkTree:
@@ -35,11 +37,13 @@ def __build_tree(self, url: str, depth: int=1):
3537
Returns:
3638
tree (ete3.Tree): Built tree.
3739
"""
40+
info(f"building tree for {url} at {depth}")
3841
root = get_node(url, depth)
3942
root_tree = Tree(name=root['url'])
4043
if root['children']:
4144
for child in root['children']:
4245
self.__append_node(root_tree, child)
46+
info(f"tree built {root_tree}")
4347
return root_tree
4448

4549
def __len__(self):

torbot/modules/log.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import logging
2+
3+
4+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', datefmt='%d-%b-%y %H:%M:%S')
5+
6+
def info(msg: str):
7+
logging.info(msg)
8+

0 commit comments

Comments
 (0)