Skip to content

Commit 11f9fa5

Browse files
authored
Merge pull request #290 from DedSecInside/improving_release_process
Improving release process
2 parents 01a485d + 0ff85f2 commit 11f9fa5

12 files changed

+106
-85
lines changed

poetry.lock

+12-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
[tool.poetry]
22
name = "torbot"
3-
version = "3.0.1"
3+
version = "3.1.1"
44
description = "OSINT for the dark web"
55
authors = ["Akeem King <[email protected]>"]
66
license = "GNU GPL"
7+
include = [".env"]
78

89
[tool.poetry.dependencies]
910
python = ">=3.9,<=3.11.4"
@@ -37,6 +38,7 @@ validators = "0.20.0"
3738
yattag = "1.14.0"
3839
treelib = "^1.6.1"
3940
numpy = "1.24.4"
41+
unipath = "^1.1"
4042

4143
[tool.poetry.dev-dependencies]
4244

requirements.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ idna==3.3 ; python_version >= "3.9" and python_full_version <= "3.11.4"
77
igraph==0.10.6 ; python_version >= "3.9" and python_full_version <= "3.11.4"
88
joblib==1.2.0 ; python_version >= "3.9" and python_full_version <= "3.11.4"
99
macholib==1.16 ; python_version >= "3.9" and python_full_version <= "3.11.4"
10-
numpy==1.25.2 ; python_version >= "3.9" and python_full_version <= "3.11.4"
10+
numpy==1.24.4 ; python_version >= "3.9" and python_full_version <= "3.11.4"
1111
pefile==2023.2.7 ; python_version >= "3.9" and python_full_version <= "3.11.4" and sys_platform == "win32"
1212
progress==1.6 ; python_version >= "3.9" and python_full_version <= "3.11.4"
1313
pyinstaller-hooks-contrib==2022.7 ; python_version >= "3.9" and python_full_version <= "3.11.4"
@@ -19,15 +19,16 @@ requests-mock==1.9.3 ; python_version >= "3.9" and python_full_version <= "3.11.
1919
requests==2.31.0 ; python_version >= "3.9" and python_full_version <= "3.11.4"
2020
scikit-learn==1.3.0 ; python_version >= "3.9" and python_full_version <= "3.11.4"
2121
scipy==1.10.0 ; python_version >= "3.9" and python_full_version <= "3.11.4"
22-
setuptools==68.0.0 ; python_version >= "3.9" and python_full_version <= "3.11.4"
22+
setuptools==68.1.2 ; python_version >= "3.9" and python_full_version <= "3.11.4"
2323
six==1.16.0 ; python_version >= "3.9" and python_full_version <= "3.11.4"
2424
sklearn==0.0 ; python_version >= "3.9" and python_full_version <= "3.11.4"
2525
soupsieve==2.3.2.post1 ; python_version >= "3.9" and python_full_version <= "3.11.4"
2626
termcolor==1.1.0 ; python_version >= "3.9" and python_full_version <= "3.11.4"
2727
texttable==1.6.4 ; python_version >= "3.9" and python_full_version <= "3.11.4"
2828
threadpoolctl==3.1.0 ; python_version >= "3.9" and python_full_version <= "3.11.4"
2929
threadsafe==1.0.0 ; python_version >= "3.9" and python_full_version <= "3.11.4"
30-
treelib==1.6.4 ; python_version >= "3.9" and python_full_version <= "3.11.4"
30+
treelib==1.7.0 ; python_version >= "3.9" and python_full_version <= "3.11.4"
31+
unipath==1.1 ; python_version >= "3.9" and python_full_version <= "3.11.4"
3132
urllib3==1.26.9 ; python_version >= "3.9" and python_full_version <= "3.11.4"
3233
validators==0.20.0 ; python_version >= "3.9" and python_full_version <= "3.11.4"
3334
yattag==1.14.0 ; python_version >= "3.9" and python_full_version <= "3.11.4"

scripts/build.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
echo "Building distributable..."
4+
poetry build
5+
echo
6+
7+
echo "Publishing..."
8+
poetry publish

install.sh renamed to scripts/install.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ cd gotor/cmd/main
1818
go install gotor.go
1919
echo "Gotor installed. Run with 'gotor'."
2020

21-
cd ../../..
21+
cd ../../..

scripts/remove.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#! /bin/bash
2+
3+
echo "Removing torbot as library..."
4+
pip uninstall torbot
5+
echo
6+
7+
echo "Removing torbot as module..."
8+
python -m pip uninstall torbot

scripts/update-requirements.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#! /bin/bash
2+
3+
echo "Writing requirements.txt..."
4+
poetry export --without-hashes --format=requirements.txt > requirements.txt
5+
echo "requirements.txt updated..."

torbot/modules/collect_data.py

+20-22
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,30 @@
33
"""
44
import datetime
55
import uuid
6-
6+
import os
77
import requests
8+
89
from bs4 import BeautifulSoup
910
from progress.bar import Bar
1011
from threadsafe.safe_csv import SafeDictWriter
1112

12-
from .utils import join_local_path
13+
from .config import get_data_directory
1314
from .validators import validate_link
1415
from .log import debug
1516

1617

17-
def parse_links(html: str):
18-
"""Parses HTML page to extract links.
19-
20-
Returns:
21-
(list): List of all valid links found.
18+
def parse_links(html: str) -> list[str]:
19+
"""
20+
Finds all anchor tags and parses the href attribute.
2221
"""
2322
soup = BeautifulSoup(html, 'html.parser')
2423
tags = soup.find_all('a')
2524
return [tag['href'] for tag in tags if validate_link(tag['href'])]
2625

2726

28-
def parse_meta_tags(soup: BeautifulSoup):
29-
"""Retrieve all meta elements from HTML object.
30-
31-
Returns:
32-
list: List containing content from meta tags
27+
def parse_meta_tags(soup: BeautifulSoup) -> list[object]:
28+
"""
29+
Parses all meta tags.
3330
"""
3431
meta_tags = soup.find_all('meta')
3532
content_list = list()
@@ -38,23 +35,23 @@ def parse_meta_tags(soup: BeautifulSoup):
3835
return content_list
3936

4037

41-
def get_links(url: str):
38+
def get_links(url: str) -> list[str]:
39+
"""
40+
Returns all valid links found on the URL.
41+
"""
4242
resp = requests.get(url)
4343
links = parse_links(resp.text)
4444
return links
4545

4646

47-
default_url = 'https://thehiddenwiki.org'
48-
49-
50-
def collect_data(user_url: str):
51-
url = user_url if user_url is not None else default_url
47+
def collect_data(url: str = 'https://thehiddenwiki.org'):
5248
print(f"Gathering data for {url}")
5349
links = get_links(url)
5450
current_time = datetime.datetime.now().isoformat()
5551
file_name = f'torbot_{current_time}.csv'
56-
file_path = join_local_path(file_name)
57-
with open(file_path, 'w+') as outcsv:
52+
data_directory = get_data_directory()
53+
local_file_path = os.path.join(data_directory, file_name)
54+
with open(local_file_path, 'w+') as outcsv:
5855
fieldnames = ['ID', 'Title', 'Metadata', 'Content']
5956
writer = SafeDictWriter(outcsv, fieldnames=fieldnames)
6057
bar = Bar('Processing...', max=len(links))
@@ -71,8 +68,9 @@ def collect_data(user_url: str):
7168
}
7269
writer.writerow(entry)
7370
except requests.exceptions.RequestException as e:
71+
print(f"Failed to connect to [{link}].")
7472
debug(e)
75-
debug(f"Failed to connect to [{link}].")
7673
bar.next()
7774
bar.finish()
78-
print(f'Data has been saved to {file_path}.')
75+
76+
print(f'Data has been saved to {local_file_path}.')

torbot/modules/config.py

+31-15
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,42 @@
22
import logging
33

44
from dotenv import load_dotenv
5+
from inspect import getsourcefile
6+
from unipath import Path
7+
8+
9+
config_file_path = (os.path.abspath(getsourcefile(lambda: 0)))
10+
modules_directory = Path(config_file_path).parent
11+
torbot_directory = modules_directory.parent
12+
project_root_directory = torbot_directory.parent
13+
dotenv_path = os.path.join(project_root_directory, '.env')
14+
load_dotenv(dotenv_path=dotenv_path, verbose=True)
515

6-
load_dotenv()
716
port = os.getenv("PORT")
817
host = os.getenv("HOST")
9-
data_directory = os.getenv('TORBOT_DATA_DIR')
1018

11-
log_level_str = os.getenv("LOG_LEVEL").lower() if os.getenv("LOG_LEVEL") else "info"
12-
LOG_LEVELS = {
13-
"info": logging.INFO,
14-
"error": logging.ERROR,
15-
"debug": logging.DEBUG,
16-
"warning": logging.WARNING,
17-
}
1819

20+
def get_log_level() -> int:
21+
log_level_str = os.getenv('LOG_LEVEL')
22+
if log_level_str:
23+
log_level_str = log_level_str.lower()
24+
mapping = logging.getLevelNamesMapping()
25+
if log_level_str in mapping:
26+
return mapping[log_level_str]
27+
return logging.INFO
28+
29+
30+
def get_data_directory():
31+
data_directory = os.getenv('TORBOT_DATA_DIR')
32+
# if a path is not set, write data to the config directory
33+
if not data_directory:
34+
data_directory = project_root_directory
1935

20-
def get_log_level():
21-
for str_input, log_level in LOG_LEVELS.items():
22-
if log_level_str == str_input:
23-
return log_level
36+
if data_directory.strip() == "":
37+
data_directory = project_root_directory
2438

39+
# create directory if it doesn't exist
40+
if not os.path.exists(data_directory):
41+
os.mkdir(data_directory)
2542

26-
if not os.path.exists(data_directory):
27-
os.mkdir(data_directory)
43+
return data_directory

torbot/modules/linktree.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
"""
22
Module is used for analyzing link relationships
33
"""
4+
import os
5+
46
from treelib import Tree, exceptions
57

68
from .api import get_node
7-
from .utils import join_local_path
9+
from .config import get_data_directory
810
from .log import debug
911

1012

@@ -67,15 +69,17 @@ def save(self, file_name: str):
6769
Saves LinkTree to file with given file_name
6870
Current file types supported are .txt
6971
"""
70-
debug(f"saving link tree as {file_name}")
71-
file_path = join_local_path(file_name)
72+
print(f"saving link tree as {file_name}")
73+
data_directory = get_data_directory()
74+
file_path = os.path.join(data_directory, file_name)
7275
try:
7376
self._tree.save2file(file_path)
7477
except Exception as e:
75-
debug(f"failed to save link tree to {file_path}")
78+
print(f"failed to save link tree to {file_path}")
79+
debug(e)
7680
raise e
7781

78-
debug(f"file saved successfully to {file_path}")
82+
print(f"file saved successfully to {file_path}")
7983

8084
def show(self):
8185
"""

torbot/modules/savefile.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
"""
44
import json
55
import time
6+
import os
67

7-
from .utils import join_local_path
8+
from .config import get_data_directory
89

910

1011
def saveJson(datatype: str, data: list):
@@ -20,7 +21,9 @@ def saveJson(datatype: str, data: list):
2021
"""
2122
timestr = time.strftime("%Y%m%d-%H%M%S")
2223
file_name = "TorBot-Export-" + datatype + timestr + ".json"
23-
file_path = join_local_path(file_name)
24+
data_directory = get_data_directory()
25+
file_path = os.path.join(data_directory, file_name)
26+
2427
# Json File Creation
2528
with open(file_path, 'w+') as f:
2629
# Store data in Json format

torbot/modules/utils.py

-35
This file was deleted.

0 commit comments

Comments
 (0)