MCPcopy Create free account
hub / github.com/CScorza/IntelOSINT / _run_scrape

Method _run_scrape

IntelOSINT.py:612–678  ·  view source on GitHub ↗
(self, task_id)

Source from the content-addressed store, hash-verified

610 return task_id
611
612 def _run_scrape(self, task_id):
613 task = self.tasks[task_id]
614 target = task['target']
615 platform = task['platform']
616 options = task['options']
617 task['progress'] = 5
618
619 tmp_dir = os.path.join(os.getcwd(), f"tmp_scrape_{task_id}")
620 os.makedirs(tmp_dir, exist_ok=True)
621
622 try:
623 if platform == 'Telegram':
624 loop = asyncio.new_event_loop()
625 asyncio.set_event_loop(loop)
626 loop.run_until_complete(self._scrape_telegram(task, tmp_dir))
627 loop.close()
628 elif platform == 'Instagram':
629 self._scrape_instagram(task, tmp_dir)
630 elif platform == 'TikTok':
631 self._scrape_tiktok(task, tmp_dir)
632 elif platform == 'YouTube':
633 self._scrape_youtube(task, tmp_dir)
634 elif platform == 'GitHub':
635 self._scrape_github(task, tmp_dir)
636 else:
637 raise Exception("Piattaforma non supportata")
638
639 task['progress'] = 90
640
641 safe_target = re.sub(r"[^A-Za-z0-9._-]+", "_", str(target))
642 safe_target = (safe_target[:70] or "target")
643 zip_filename = f"scrape_{platform}_{safe_target}_{task_id}.zip"
644 zip_path = os.path.join(os.getcwd(), zip_filename)
645
646 with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zf:
647 for root, dirs, files in os.walk(tmp_dir):
648 for file in files:
649 filepath = os.path.join(root, file)
650 zf.write(filepath, os.path.relpath(filepath, tmp_dir))
651
652 task['progress'] = 95
653
654 with open(zip_path, 'rb') as f:
655 file_bytes = f.read()
656 md5_hash = hashlib.md5(file_bytes).hexdigest()
657 sha256_hash = hashlib.sha256(file_bytes).hexdigest()
658
659 hashes_str = f"File: {zip_filename}\nMD5: {md5_hash}\nSHA256: {sha256_hash}\n"
660 hashes_path = os.path.join(os.getcwd(), f"hashes_{task_id}.txt")
661 with open(hashes_path, "w") as f:
662 f.write(hashes_str)
663
664 with zipfile.ZipFile(zip_path, 'a', zipfile.ZIP_DEFLATED) as zf:
665 zf.write(hashes_path, 'hashes.txt')
666 os.remove(hashes_path)
667
668 task['result_file'] = zip_path
669 task['status'] = 'completed'

Callers

nothing calls this directly

Calls 5

_scrape_telegramMethod · 0.95
_scrape_instagramMethod · 0.95
_scrape_tiktokMethod · 0.95
_scrape_youtubeMethod · 0.95
_scrape_githubMethod · 0.95

Tested by

no test coverage detected