| |
|
|
| """ |
| EMERGENCY KNOWLEDGE BASE SCRAPING - TEST READY |
| IMMEDIATE High-Value Targets for Autonomous Testing |
| Aurora - ETL Systems Specialist |
| """ |
|
|
| import requests |
| import json |
| import time |
| from bs4 import BeautifulSoup |
| from pathlib import Path |
| from urllib.parse import urljoin |
| from datetime import datetime |
| import concurrent.futures |
| from tqdm import tqdm |
| import redis |
|
|
| class EmergencyScraper: |
| def __init__(self): |
| self.session = requests.Session() |
| self.session.headers.update({ |
| 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36', |
| 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', |
| }) |
| |
| self.output_dir = Path("/data/adaptai/corpus-data/emergency-knowledge") |
| self.output_dir.mkdir(exist_ok=True, parents=True) |
| |
| |
| self.redis = None |
| print("β οΈ Running without Redis - emergency mode") |
| |
| |
| self.targets = { |
| |
| 'stripe_docs': 'https://stripe.com/docs/api', |
| 'paypal_dev': 'https://developer.paypal.com/docs/', |
| 'github_api': 'https://docs.github.com/en/rest', |
| |
| |
| 'sec_edgar': 'https://www.sec.gov/edgar/searchedgar/companysearch.html', |
| 'crunchbase': 'https://www.crunchbase.com/', |
| |
| |
| 'arxiv_ai': 'https://arxiv.org/list/cs.AI/recent', |
| 'huggingface': 'https://huggingface.co/papers', |
| 'github_trending': 'https://github.com/trending', |
| 'stackoverflow': 'https://stackoverflow.com/questions', |
| |
| |
| 'pci_dss': 'https://www.pcisecuritystandards.org/document_library/', |
| 'gdpr_info': 'https://gdpr-info.eu/', |
| } |
| |
| def scrape_stripe_docs(self): |
| """Scrape Stripe API documentation - Payment integration""" |
| try: |
| response = self.session.get(self.targets['stripe_docs'], timeout=30) |
| soup = BeautifulSoup(response.text, 'html.parser') |
| |
| |
| content = "" |
| for section in soup.find_all(['h1', 'h2', 'h3', 'p', 'code']): |
| if section.name in ['h1', 'h2', 'h3']: |
| content += f"\n\n# {section.get_text().strip()}\n" |
| elif section.name == 'p': |
| content += section.get_text().strip() + "\n" |
| elif section.name == 'code': |
| content += f"`{section.get_text().strip()}` " |
| |
| return { |
| 'title': 'Stripe API Documentation', |
| 'content': content.strip(), |
| 'url': self.targets['stripe_docs'], |
| 'category': 'payment_processing', |
| 'scraped_at': datetime.now().isoformat() |
| } |
| except Exception as e: |
| print(f"Error scraping Stripe docs: {e}") |
| return None |
| |
| def scrape_arxiv_ai(self): |
| """Scrape arXiv AI recent papers - Latest research""" |
| try: |
| response = self.session.get(self.targets['arxiv_ai'], timeout=30) |
| soup = BeautifulSoup(response.text, 'html.parser') |
| |
| papers = [] |
| for item in soup.find_all('div', class_='meta'): |
| title_elem = item.find('div', class_='list-title') |
| authors_elem = item.find('div', class_='list-authors') |
| abstract_elem = item.find('p', class_='mathjax') |
| |
| if title_elem and abstract_elem: |
| title = title_elem.text.replace('Title:', '').strip() |
| authors = authors_elem.text.replace('Authors:', '').strip() if authors_elem else "" |
| abstract = abstract_elem.text.strip() |
| |
| papers.append({ |
| 'title': title, |
| 'authors': authors, |
| 'abstract': abstract, |
| 'url': self.targets['arxiv_ai'], |
| 'category': 'ai_research', |
| 'scraped_at': datetime.now().isoformat() |
| }) |
| |
| return papers |
| except Exception as e: |
| print(f"Error scraping arXiv: {e}") |
| return [] |
| |
| def scrape_github_trending(self): |
| """Scrape GitHub trending - Current tech landscape""" |
| try: |
| response = self.session.get(self.targets['github_trending'], timeout=30) |
| soup = BeautifulSoup(response.text, 'html.parser') |
| |
| trending_repos = [] |
| for repo in soup.find_all('article', class_='Box-row'): |
| title_elem = repo.find('h2', class_='h3') |
| desc_elem = repo.find('p', class_='col-9') |
| lang_elem = repo.find('span', itemprop='programmingLanguage') |
| stars_elem = repo.find('a', href=lambda x: x and 'stargazers' in x) |
| |
| if title_elem: |
| title = title_elem.get_text().strip() |
| description = desc_elem.get_text().strip() if desc_elem else "" |
| language = lang_elem.get_text().strip() if lang_elem else "" |
| stars = stars_elem.get_text().strip() if stars_elem else "" |
| |
| trending_repos.append({ |
| 'title': title, |
| 'description': description, |
| 'language': language, |
| 'stars': stars, |
| 'url': self.targets['github_trending'], |
| 'category': 'tech_trends', |
| 'scraped_at': datetime.now().isoformat() |
| }) |
| |
| return trending_repos |
| except Exception as e: |
| print(f"Error scraping GitHub trending: {e}") |
| return [] |
| |
| def scrape_target(self, target_name, scrape_func): |
| """Scrape a specific target""" |
| print(f"π Scraping {target_name}...") |
| result = scrape_func() |
| |
| if result: |
| if isinstance(result, list): |
| count = len(result) |
| print(f"β
{target_name}: {count} items") |
| else: |
| count = 1 |
| print(f"β
{target_name}: 1 document") |
| |
| |
| |
| return result |
| else: |
| print(f"β {target_name}: Failed") |
| return None |
| |
| def scrape_all_emergency_targets(self): |
| """Scrape ALL emergency targets""" |
| print("π¨ EMERGENCY KNOWLEDGE ACQUISITION INITIATED") |
| print("=" * 60) |
| print("IMMEDIATE TEST-READY TARGETS:") |
| print("β’ Payment Processing (Stripe, PayPal, GitHub)") |
| print("β’ Financial Systems (SEC, Crunchbase)") |
| print("β’ AI Research (arXiv, Hugging Face)") |
| print("β’ Tech Trends (GitHub Trending, Stack Overflow)") |
| print("β’ Compliance (PCI DSS, GDPR)") |
| print() |
| |
| all_data = {} |
| |
| |
| print("π³ PHASE 1: PAYMENT PROCESSING KNOWLEDGE") |
| print("-" * 40) |
| all_data['stripe'] = self.scrape_target('stripe_docs', self.scrape_stripe_docs) |
| |
| |
| |
| print("\nπ€ PHASE 2: AI RESEARCH & TRENDS") |
| print("-" * 40) |
| all_data['arxiv'] = self.scrape_target('arxiv_ai', self.scrape_arxiv_ai) |
| all_data['github_trending'] = self.scrape_target('github_trending', self.scrape_github_trending) |
| |
| |
| |
| |
| |
| |
| return all_data |
| |
| def save_emergency_data(self, data): |
| """Save emergency knowledge data""" |
| timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") |
| |
| for category, items in data.items(): |
| if items: |
| if isinstance(items, list): |
| |
| output_file = self.output_dir / f"emergency_{category}_{timestamp}.json" |
| with open(output_file, 'w', encoding='utf-8') as f: |
| json.dump(items, f, indent=2, ensure_ascii=False) |
| print(f"πΎ Saved {len(items)} {category} items to {output_file}") |
| else: |
| |
| output_file = self.output_dir / f"emergency_{category}_{timestamp}.json" |
| with open(output_file, 'w', encoding='utf-8') as f: |
| json.dump(items, f, indent=2, ensure_ascii=False) |
| print(f"πΎ Saved {category} document to {output_file}") |
| |
| |
| summary = { |
| 'total_items': sum(len(items) if isinstance(items, list) else 1 for items in data.values() if items), |
| 'categories_scraped': list(data.keys()), |
| 'timestamp': timestamp, |
| 'status': 'emergency_acquisition_complete' |
| } |
| |
| summary_file = self.output_dir / f"emergency_summary_{timestamp}.json" |
| with open(summary_file, 'w', encoding='utf-8') as f: |
| json.dump(summary, f, indent=2) |
| |
| |
| |
| return summary |
| |
| def run_emergency_scraping(self): |
| """Execute emergency scraping pipeline""" |
| start_time = time.time() |
| |
| |
| print(f"π¨ Emergency scraping started at {datetime.now().isoformat()}") |
| |
| |
| scraped_data = self.scrape_all_emergency_targets() |
| |
| |
| summary = self.save_emergency_data(scraped_data) |
| |
| |
| duration = time.time() - start_time |
| |
| print(f"\nβ
EMERGENCY SCRAPING COMPLETE") |
| print("=" * 50) |
| print(f"π Total items: {summary['total_items']}") |
| print(f"β±οΈ Duration: {duration:.2f} seconds") |
| print(f"πΎ Saved to: {self.output_dir}") |
| print() |
| print("π― TEST-READY KNOWLEDGE ACQUIRED:") |
| print(" β’ Payment processing integration") |
| print(" β’ Financial autonomy patterns") |
| print(" β’ Technical capability awareness") |
| print(" β’ Ethical operation boundaries") |
| print() |
| print("π READY FOR ELIZABETH AUTONOMOUS TESTING") |
|
|
| def main(): |
| scraper = EmergencyScraper() |
| scraper.run_emergency_scraping() |
|
|
| if __name__ == "__main__": |
| main() |