From 4aeacef07d9cd71205ea768949f5214886c6d4a2 Mon Sep 17 00:00:00 2001 From: Soxoj Date: Sat, 22 May 2021 20:23:53 +0300 Subject: [PATCH] Sort by number of data points (#105) --- maigret/maigret.py | 11 +++++++++++ maigret/report.py | 10 ++++++++++ maigret/resources/data.json | 6 +++--- tests/test_cli.py | 1 + 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/maigret/maigret.py b/maigret/maigret.py index f969c8b..e9349df 100755 --- a/maigret/maigret.py +++ b/maigret/maigret.py @@ -33,6 +33,7 @@ from .report import ( SUPPORTED_JSON_REPORT_FORMATS, save_json_report, get_plaintext_report, + sort_report_by_data_points, ) from .sites import MaigretDatabase from .submit import submit_dialog @@ -433,6 +434,13 @@ def setup_arguments_parser(): help=f"Generate a JSON report of specific type: {', '.join(SUPPORTED_JSON_REPORT_FORMATS)}" " (one report per username).", ) + + parser.add_argument( + "--reports-sorting", + default='default', + choices=('default', 'data'), + help="Method of results sorting in reports (default: in order of getting the result)", + ) return parser @@ -613,6 +621,9 @@ async def main(): notify_about_errors(results, query_notify) + if args.reports_sorting == "data": + results = sort_report_by_data_points(results) + general_results.append((username, id_type, results)) # TODO: tests diff --git a/maigret/report.py b/maigret/report.py index fb1219d..f90adba 100644 --- a/maigret/report.py +++ b/maigret/report.py @@ -36,6 +36,16 @@ def filter_supposed_data(data): return filtered_supposed_data +def sort_report_by_data_points(results): + return dict( + sorted( + results.items(), + key=lambda x: len((x[1]['status'].ids_data or {}).keys()), + reverse=True, + ) + ) + + """ REPORTS SAVING """ diff --git a/maigret/resources/data.json b/maigret/resources/data.json index f9f0db0..6d1ea01 100644 --- a/maigret/resources/data.json +++ b/maigret/resources/data.json @@ -13035,7 +13035,7 @@ "us" ], "headers": { - "authorization": "Bearer BQBFMMVu1dPwJPlnzUteNyF8xlZy7545QnhHizEHWEUQGQrRLznY5k9B9v7JdAsL-wU-Tcep51JTqBesKKY" + "authorization": "Bearer BQDV85OO3yWO4yi95C8pEH---y_0fc2KxTYWFy1SjhaoSlN0jbyS6IR7q_noWYoXN1lSA4_FYL9UmAb1e1M" }, "errors": { "Spotify is currently not available in your country.": "Access denied in your country, use proxy/vpn" @@ -14463,7 +14463,7 @@ "sec-ch-ua": "Google Chrome\";v=\"87\", \" Not;A Brand\";v=\"99\", \"Chromium\";v=\"87\"", "authorization": "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA", "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36", - "x-guest-token": "1394397954526560260" + "x-guest-token": "1396147935914733569" }, "errors": { "Bad guest token": "x-guest-token update required" @@ -14870,7 +14870,7 @@ "video" ], "headers": { - "Authorization": "jwt eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MjEyODYyODAsInVzZXJfaWQiOm51bGwsImFwcF9pZCI6NTg0NzksInNjb3BlcyI6InB1YmxpYyIsInRlYW1fdXNlcl9pZCI6bnVsbH0.mxLdaOuP260WcxBvhadTTUQyn8t75pWNhTmtZLFS-W4" + "Authorization": "jwt eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MjE3MDQ0ODAsInVzZXJfaWQiOm51bGwsImFwcF9pZCI6NTg0NzksInNjb3BlcyI6InB1YmxpYyIsInRlYW1fdXNlcl9pZCI6bnVsbH0.uJk5fpJb7c-7uuN7CKmlD13SqfNbBrCPnnOXdrdX6u8" }, "activation": { "url": "https://vimeo.com/_rv/viewer", diff --git a/tests/test_cli.py b/tests/test_cli.py index 3369164..302c3ae 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -25,6 +25,7 @@ DEFAULT_ARGS: Dict[str, Any] = { 'print_check_errors': False, 'print_not_found': False, 'proxy': None, + 'reports_sorting': 'default', 'retries': 1, 'self_check': False, 'site_list': [],