■ ■ ■ ■ ■ ■
maryam/modules/search/pastebin.py
| skipped 20 lines |
21 | 21 | | meta = { |
22 | 22 | | 'name': 'Pastebin Search', |
23 | 23 | | 'author': 'Divya Goswami', |
24 | | - | 'version': '1.0', |
| 24 | + | 'version': '1.1', |
25 | 25 | | 'description': 'Search your query in the pastebin.com and show the results as paste links.', |
26 | 26 | | 'sources': ('pastebin',), |
27 | 27 | | 'options': ( |
28 | 28 | | ('query', None, True, 'Query string', '-q', 'store', str), |
29 | 29 | | ('limit', 1, False, 'Search limit(number of pages, default=1)', '-l', 'store', int), |
30 | 30 | | ('count', 50, False, 'Number of results per page(min=10, max=100, default=50)', '-c', 'store', int), |
31 | | - | ('thread', 3, False, 'The number of engine that run per round(default=2)', '-t', 'store', int), |
32 | | - | ('engine', 'pastebin', False, 'Engine names for search', '-e', 'store', str), |
33 | 31 | | ), |
34 | 32 | | 'examples': ('pastebin -q passwords -l 15 --output',) |
35 | 33 | | } |
36 | 34 | | |
37 | | - | LINKS = [] |
38 | | - | PAGES = '' |
39 | | - | |
40 | | - | def search(self, name, q, q_formats, limit, count): |
41 | | - | global PAGES,LINKS |
42 | | - | engine = getattr(self, name) |
43 | | - | q = q_formats[f"{name}_q"] if f"{name}_q" in q_formats else q_formats['default_q'] |
44 | | - | varnames = engine.__init__.__code__.co_varnames |
45 | | - | if 'limit' in varnames and 'count' in varnames: |
46 | | - | attr = engine(q, limit, count) |
47 | | - | elif 'limit' in varnames: |
48 | | - | attr = engine(q, limit) |
49 | | - | else: |
50 | | - | attr = engine(q) |
51 | | - | |
52 | | - | attr.run_crawl() |
53 | | - | LINKS += attr.links |
54 | | - | PAGES += attr.pages |
55 | 35 | | |
56 | 36 | | def module_api(self): |
57 | 37 | | query = self.options['query'] |
58 | 38 | | limit = self.options['limit'] |
59 | 39 | | count = self.options['count'] |
60 | | - | engine = self.options['engine'].split(',') |
61 | 40 | | output = {'pastes': []} |
62 | | - | q_formats = { |
63 | | - | 'default_q': f"{query}" |
64 | | - | } |
65 | | - | self.thread(search, self.options['thread'], engine, query, q_formats, limit, count, meta['sources']) |
66 | | - | links = list(self.reglib().filter(r"https?://pastebin\.com/[\w\d]{2,}", list(set(LINKS)))) |
67 | | - | self.verbose('Rearranging paste links [give it a few seconds]...') |
68 | | - | for link in links: |
69 | | - | heading = re.search(r"pastebin\.com/([\w\d]+)", link) |
70 | | - | if heading: |
71 | | - | head_raw = f"https://pastebin.com/raw/{heading.group(1)}" |
72 | | - | try: |
73 | | - | head_req = self.request(url=head_raw).text.splitlines()[0].lstrip() |
74 | | - | except Exception as e: |
75 | | - | self.verbose('Pastebin is missed!') |
76 | | - | else: |
77 | | - | head_title = f"{query} pastes {head_req[:30]}...".ljust(10, ' ') |
78 | | - | title = head_title.title() |
79 | | - | output['pastes'].append([link, title]) |
| 41 | + | pastebin = self.pastebin(query, limit, count) |
| 42 | + | pastebin.run_crawl() |
| 43 | + | output['pastes'] = pastebin.links_and_titles |
80 | 44 | | self.save_gather(output, 'search/pastebin', query, output=self.options.get('output')) |
81 | 45 | | return output |
82 | 46 | | |
| skipped 8 lines |