mirror of
https://github.com/soxoj/maigret.git
synced 2026-05-07 06:24:35 +00:00
Added text report to CLI output
This commit is contained in:
@@ -32,6 +32,7 @@ from .report import (
|
|||||||
save_txt_report,
|
save_txt_report,
|
||||||
SUPPORTED_JSON_REPORT_FORMATS,
|
SUPPORTED_JSON_REPORT_FORMATS,
|
||||||
save_json_report,
|
save_json_report,
|
||||||
|
get_plaintext_report,
|
||||||
)
|
)
|
||||||
from .sites import MaigretDatabase
|
from .sites import MaigretDatabase
|
||||||
from .submit import submit_dialog
|
from .submit import submit_dialog
|
||||||
@@ -646,6 +647,12 @@ async def main():
|
|||||||
filename = report_filepath_tpl.format(username=username, postfix='.pdf')
|
filename = report_filepath_tpl.format(username=username, postfix='.pdf')
|
||||||
save_pdf_report(filename, report_context)
|
save_pdf_report(filename, report_context)
|
||||||
query_notify.warning(f'PDF report on all usernames saved in {filename}')
|
query_notify.warning(f'PDF report on all usernames saved in {filename}')
|
||||||
|
|
||||||
|
text_report = get_plaintext_report(report_context)
|
||||||
|
if text_report:
|
||||||
|
query_notify.info('Short text report:')
|
||||||
|
print(text_report)
|
||||||
|
|
||||||
# update database
|
# update database
|
||||||
db.save_to_file(args.db_file)
|
db.save_to_file(args.db_file)
|
||||||
|
|
||||||
|
|||||||
+10
-3
@@ -205,13 +205,20 @@ class QueryNotifyPrint(QueryNotify):
|
|||||||
else:
|
else:
|
||||||
print(f"[*] {title} {message} on:")
|
print(f"[*] {title} {message} on:")
|
||||||
|
|
||||||
def warning(self, message, symbol="-"):
|
def _colored_print(self, fore_color, msg):
|
||||||
msg = f"[{symbol}] {message}"
|
|
||||||
if self.color:
|
if self.color:
|
||||||
print(Style.BRIGHT + Fore.YELLOW + msg)
|
print(Style.BRIGHT + fore_color + msg)
|
||||||
else:
|
else:
|
||||||
print(msg)
|
print(msg)
|
||||||
|
|
||||||
|
def warning(self, message, symbol="-"):
|
||||||
|
msg = f"[{symbol}] {message}"
|
||||||
|
self._colored_print(Fore.YELLOW, msg)
|
||||||
|
|
||||||
|
def info(self, message, symbol="*"):
|
||||||
|
msg = f"[{symbol}] {message}"
|
||||||
|
self._colored_print(Fore.BLUE, msg)
|
||||||
|
|
||||||
def update(self, result, is_similar=False):
|
def update(self, result, is_similar=False):
|
||||||
"""Notify Update.
|
"""Notify Update.
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,17 @@ def save_json_report(filename: str, username: str, results: dict, report_type: s
|
|||||||
generate_json_report(username, results, f, report_type=report_type)
|
generate_json_report(username, results, f, report_type=report_type)
|
||||||
|
|
||||||
|
|
||||||
|
def get_plaintext_report(context: dict) -> str:
|
||||||
|
output = (context['brief'] + " ").replace('. ', '.\n')
|
||||||
|
interests = list(map(lambda x: x[0], context.get('interests_tuple_list', [])))
|
||||||
|
countries = list(map(lambda x: x[0], context.get('countries_tuple_list', [])))
|
||||||
|
if countries:
|
||||||
|
output += f'Countries: {", ".join(countries)}\n'
|
||||||
|
if interests:
|
||||||
|
output += f'Interests (tags): {", ".join(interests)}\n'
|
||||||
|
return output.strip()
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
REPORTS GENERATING
|
REPORTS GENERATING
|
||||||
"""
|
"""
|
||||||
@@ -215,6 +226,7 @@ def generate_report_context(username_results: list):
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
"username": first_username,
|
"username": first_username,
|
||||||
|
# TODO: return brief list
|
||||||
"brief": brief,
|
"brief": brief,
|
||||||
"results": username_results,
|
"results": username_results,
|
||||||
"first_seen": first_seen,
|
"first_seen": first_seen,
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ from maigret.report import (
|
|||||||
generate_report_template,
|
generate_report_template,
|
||||||
generate_report_context,
|
generate_report_context,
|
||||||
generate_json_report,
|
generate_json_report,
|
||||||
|
get_plaintext_report,
|
||||||
)
|
)
|
||||||
from maigret.result import QueryResult, QueryStatus
|
from maigret.result import QueryResult, QueryStatus
|
||||||
from maigret.sites import MaigretSite
|
from maigret.sites import MaigretSite
|
||||||
@@ -346,3 +347,13 @@ def test_pdf_report():
|
|||||||
save_pdf_report(report_name, context)
|
save_pdf_report(report_name, context)
|
||||||
|
|
||||||
assert os.path.exists(report_name)
|
assert os.path.exists(report_name)
|
||||||
|
|
||||||
|
|
||||||
|
def test_text_report():
|
||||||
|
context = generate_report_context(TEST)
|
||||||
|
report_text = get_plaintext_report(context)
|
||||||
|
|
||||||
|
for brief_part in SUPPOSED_BRIEF.split():
|
||||||
|
assert brief_part in report_text
|
||||||
|
assert 'us' in report_text
|
||||||
|
assert 'photo' in report_text
|
||||||
|
|||||||
Reference in New Issue
Block a user