| skipped 12 lines |
13 | 13 | | from .checking import * |
14 | 14 | | from .notify import QueryNotifyPrint |
15 | 15 | | from .report import save_csv_report, save_xmind_report, save_html_report, save_pdf_report, \ |
16 | | - | generate_report_context, save_txt_report |
| 16 | + | generate_report_context, save_txt_report, SUPPORTED_JSON_REPORT_FORMATS, check_supported_json_format, \ |
| 17 | + | save_json_report |
17 | 18 | | from .submit import submit_dialog |
18 | 19 | | |
19 | 20 | | __version__ = '0.1.13' |
| skipped 36 lines |
56 | 57 | | action="store", dest="proxy", default=None, |
57 | 58 | | help="Make requests over a proxy. e.g. socks5://127.0.0.1:1080" |
58 | 59 | | ) |
59 | | - | parser.add_argument("--json", "-j", metavar="JSON_FILE", |
60 | | - | dest="json_file", default=None, |
61 | | - | help="Load data from a JSON file or an online, valid, JSON file.") |
| 60 | + | parser.add_argument("--db", metavar="DB_FILE", |
| 61 | + | dest="db_file", default=None, |
| 62 | + | help="Load Maigret database from a JSON file or an online, valid, JSON file.") |
62 | 63 | | parser.add_argument("--cookies-jar-file", metavar="COOKIE_FILE", |
63 | 64 | | dest="cookie_file", default=None, |
64 | 65 | | help="File with cookies.") |
| skipped 26 lines |
91 | 92 | | action="store_true", dest="print_check_errors", default=False, |
92 | 93 | | help="Print errors messages: connection, captcha, site country ban, etc." |
93 | 94 | | ) |
94 | | - | parser.add_argument("--submit", |
| 95 | + | parser.add_argument("--submit", metavar='EXISTING_USER_URL', |
95 | 96 | | type=str, dest="new_site_to_submit", default=False, |
96 | 97 | | help="URL of existing profile in new site to submit." |
97 | 98 | | ) |
| skipped 60 lines |
158 | 159 | | dest="pdf", default=False, |
159 | 160 | | help="Generate a PDF report (general report on all usernames)." |
160 | 161 | | ) |
| 162 | + | parser.add_argument("-J", "--json", |
| 163 | + | action="store", metavar='REPORT_TYPE', |
| 164 | + | dest="json", default='', type=check_supported_json_format, |
| 165 | + | help=f"Generate a JSON report of specific type: {', '.join(SUPPORTED_JSON_REPORT_FORMATS)}" |
| 166 | + | " (one report per username)." |
| 167 | + | ) |
161 | 168 | | |
162 | 169 | | args = parser.parse_args() |
163 | 170 | | |
| skipped 42 lines |
206 | 213 | | if args.tags: |
207 | 214 | | args.tags = list(set(str(args.tags).split(','))) |
208 | 215 | | |
209 | | - | if args.json_file is None: |
210 | | - | args.json_file = \ |
| 216 | + | if args.db_file is None: |
| 217 | + | args.db_file = \ |
211 | 218 | | os.path.join(os.path.dirname(os.path.realpath(__file__)), |
212 | 219 | | "resources/data.json" |
213 | 220 | | ) |
| skipped 9 lines |
223 | 230 | | color=not args.no_color) |
224 | 231 | | |
225 | 232 | | # Create object with all information about sites we are aware of. |
226 | | - | db = MaigretDatabase().load_from_file(args.json_file) |
| 233 | + | db = MaigretDatabase().load_from_file(args.db_file) |
227 | 234 | | get_top_sites_for_id = lambda x: db.ranked_sites_dict(top=args.top_sites, tags=args.tags, |
228 | 235 | | names=args.site_list, |
229 | 236 | | disabled=False, id_type=x) |
| skipped 3 lines |
233 | 240 | | if args.new_site_to_submit: |
234 | 241 | | is_submitted = await submit_dialog(db, args.new_site_to_submit) |
235 | 242 | | if is_submitted: |
236 | | - | db.save_to_file(args.json_file) |
| 243 | + | db.save_to_file(args.db_file) |
237 | 244 | | |
238 | 245 | | # Database self-checking |
239 | 246 | | if args.self_check: |
| skipped 1 lines |
241 | 248 | | is_need_update = await self_check(db, site_data, logger, max_connections=args.connections) |
242 | 249 | | if is_need_update: |
243 | 250 | | if input('Do you want to save changes permanently? [yYnN]\n').lower() == 'y': |
244 | | - | db.save_to_file(args.json_file) |
| 251 | + | db.save_to_file(args.db_file) |
245 | 252 | | print('Database was successfully updated.') |
246 | 253 | | else: |
247 | 254 | | print('Updates will be applied only for current search session.') |
| skipped 91 lines |
339 | 346 | | save_txt_report(filename, username, results) |
340 | 347 | | query_notify.warning(f'TXT report for {username} saved in {filename}') |
341 | 348 | | |
| 349 | + | if args.json: |
| 350 | + | filename = report_filepath_tpl.format(username=username, postfix=f'_{args.json}.json') |
| 351 | + | save_json_report(filename, username, results, report_type=args.json) |
| 352 | + | query_notify.warning(f'JSON {args.json} report for {username} saved in {filename}') |
| 353 | + | |
| 354 | + | |
342 | 355 | | # reporting for all the result |
343 | 356 | | if general_results: |
344 | 357 | | if args.html or args.pdf: |
| skipped 12 lines |
357 | 370 | | save_pdf_report(filename, report_context) |
358 | 371 | | query_notify.warning(f'PDF report on all usernames saved in {filename}') |
359 | 372 | | # update database |
360 | | - | db.save_to_file(args.json_file) |
| 373 | + | db.save_to_file(args.db_file) |
361 | 374 | | |
362 | 375 | | |
363 | 376 | | def run(): |
| skipped 11 lines |