| skipped 1 lines |
2 | 2 | | Maigret main module |
3 | 3 | | """ |
4 | 4 | | |
5 | | - | import aiohttp |
6 | 5 | | import asyncio |
7 | | - | import csv |
8 | | - | import http.cookiejar as cookielib |
9 | | - | import json |
10 | 6 | | import logging |
11 | 7 | | import os |
12 | 8 | | import platform |
13 | 9 | | import re |
14 | | - | import requests |
15 | 10 | | import ssl |
16 | 11 | | import sys |
| 12 | + | from argparse import ArgumentParser, RawDescriptionHelpFormatter |
| 13 | + | |
| 14 | + | import aiohttp |
| 15 | + | import requests |
17 | 16 | | import tqdm.asyncio |
18 | | - | import xmind |
19 | 17 | | from aiohttp_socks import ProxyConnector |
20 | | - | from argparse import ArgumentParser, RawDescriptionHelpFormatter |
21 | | - | from http.cookies import SimpleCookie |
22 | 18 | | from mock import Mock |
23 | 19 | | from python_socks import _errors as proxy_errors |
24 | 20 | | from socid_extractor import parse, extract, __version__ as socid_version |
25 | 21 | | |
26 | | - | from .activation import ParsingActivator |
| 22 | + | from .activation import ParsingActivator, import_aiohttp_cookies |
27 | 23 | | from .notify import QueryNotifyPrint |
28 | 24 | | from .report import save_csv_report, save_xmind_report, save_html_report, save_pdf_report, \ |
29 | | - | generate_report_context, save_txt_report |
| 25 | + | generate_report_context, save_txt_report |
30 | 26 | | from .result import QueryResult, QueryStatus |
31 | 27 | | from .sites import MaigretDatabase, MaigretSite |
32 | 28 | | |
| skipped 19 lines |
52 | 48 | | } |
53 | 49 | | |
54 | 50 | | unsupported_characters = '#' |
55 | | - | |
56 | | - | cookies_file = 'cookies.txt' |
57 | | - | |
58 | 51 | | |
59 | 52 | | async def get_response(request_future, site_name, logger): |
60 | 53 | | html_text = None |
| skipped 249 lines |
310 | 303 | | async def maigret(username, site_dict, query_notify, logger, |
311 | 304 | | proxy=None, timeout=None, recursive_search=False, |
312 | 305 | | id_type='username', debug=False, forced=False, |
313 | | - | max_connections=100, no_progressbar=False): |
| 306 | + | max_connections=100, no_progressbar=False, |
| 307 | + | cookies=None): |
314 | 308 | | """Main search func |
315 | 309 | | |
316 | 310 | | Checks for existence of username on various social media sites. |
| skipped 31 lines |
348 | 342 | | connector = ProxyConnector.from_url(proxy) if proxy else aiohttp.TCPConnector(ssl=False) |
349 | 343 | | # connector = aiohttp.TCPConnector(ssl=False) |
350 | 344 | | connector.verify_ssl=False |
351 | | - | session = aiohttp.ClientSession(connector=connector, trust_env=True) |
| 345 | + | |
| 346 | + | cookie_jar = None |
| 347 | + | if cookies: |
| 348 | + | cookie_jar = await import_aiohttp_cookies(cookies) |
| 349 | + | |
| 350 | + | session = aiohttp.ClientSession(connector=connector, trust_env=True, cookie_jar=cookie_jar) |
352 | 351 | | |
353 | 352 | | if logger.level == logging.DEBUG: |
354 | 353 | | future = session.get(url='https://icanhazip.com') |
| skipped 24 lines |
379 | 378 | | results_site['username'] = username |
380 | 379 | | results_site['parsing_enabled'] = recursive_search |
381 | 380 | | results_site['url_main'] = site.url_main |
| 381 | + | results_site['cookies'] = cookie_jar and cookie_jar.filter_cookies(site.url_main) or None |
382 | 382 | | |
383 | 383 | | headers = { |
384 | 384 | | 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11.1; rv:55.0) Gecko/20100101 Firefox/55.0', |
| skipped 39 lines |
424 | 424 | | username=username, |
425 | 425 | | ) |
426 | 426 | | |
| 427 | + | for k, v in site.get_params.items(): |
| 428 | + | url_probe += f'&{k}={v}' |
427 | 429 | | |
428 | 430 | | if site.check_type == 'status_code' and site.request_head_only: |
429 | 431 | | # In most cases when we are detecting by status code, |
| skipped 16 lines |
446 | 448 | | # The final result of the request will be what is available. |
447 | 449 | | allow_redirects = True |
448 | 450 | | |
449 | | - | # TODO: cookies using |
450 | | - | # def parse_cookies(cookies_str): |
451 | | - | # cookies = SimpleCookie() |
452 | | - | # cookies.load(cookies_str) |
453 | | - | # return {key: morsel.value for key, morsel in cookies.items()} |
454 | | - | # |
455 | | - | # if os.path.exists(cookies_file): |
456 | | - | # cookies_obj = cookielib.MozillaCookieJar(cookies_file) |
457 | | - | # cookies_obj.load(ignore_discard=True, ignore_expires=True) |
458 | | - | |
459 | 451 | | future = request_method(url=url_probe, headers=headers, |
460 | 452 | | allow_redirects=allow_redirects, |
461 | 453 | | timeout=timeout, |
| skipped 199 lines |
661 | 653 | | parser.add_argument("--json", "-j", metavar="JSON_FILE", |
662 | 654 | | dest="json_file", default=None, |
663 | 655 | | help="Load data from a JSON file or an online, valid, JSON file.") |
| 656 | + | parser.add_argument("--cookies-jar-file", metavar="COOKIE_FILE", |
| 657 | + | dest="cookie_file", default=None, |
| 658 | + | help="File with cookies.") |
664 | 659 | | parser.add_argument("--timeout", |
665 | 660 | | action="store", metavar='TIMEOUT', |
666 | 661 | | dest="timeout", type=timeout_check, default=10, |
| skipped 220 lines |
887 | 882 | | id_type=id_type, |
888 | 883 | | debug=args.verbose, |
889 | 884 | | logger=logger, |
| 885 | + | cookies=args.cookie_file, |
890 | 886 | | forced=args.use_disabled_sites, |
891 | 887 | | max_connections=args.connections, |
892 | 888 | | ) |
| skipped 62 lines |