agent scraper
This commit is contained in:
13
agent-py-bot/agents/runner.py
Normal file
13
agent-py-bot/agents/runner.py
Normal file
@ -0,0 +1,13 @@
|
||||
import subprocess
|
||||
import re
|
||||
|
||||
|
||||
def execute_python_code(code_block):
|
||||
try:
|
||||
result = subprocess.run(['python', '-c', code_block],
|
||||
capture_output=True, text=True, timeout=5)
|
||||
return result.stdout or result.stderr
|
||||
except Exception as e:
|
||||
return f"Execution error: {str(e)}"
|
||||
|
||||
|
35
agent-py-bot/agents/webagent.py
Normal file
35
agent-py-bot/agents/webagent.py
Normal file
@ -0,0 +1,35 @@
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
import os
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
def search_news(topic):
|
||||
url = f"https://www.google.com/search?q={topic}"
|
||||
response = requests.get(url)
|
||||
soup = BeautifulSoup(response.text, 'html.parser')
|
||||
|
||||
news_data = [] # Extract relevant information here
|
||||
return news_data
|
||||
|
||||
def save_data(data, folder):
|
||||
if not os.path.exists(folder):
|
||||
os.makedirs(folder)
|
||||
|
||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
file_path = os.path.join(folder, f"data_{timestamp}.json")
|
||||
|
||||
with open(file_path, 'w') as file:
|
||||
json.dump(data, file)
|
||||
|
||||
def summarize_data(data):
|
||||
summary = "Summarized information" # Replace with actual summarization logic
|
||||
return summary
|
||||
|
||||
def run_web_agent(topic, folder):
|
||||
print(f"Running web agent for topic: {topic}")
|
||||
news_data = search_news(topic)
|
||||
save_data(news_data, folder)
|
||||
summary = summarize_data(news_data)
|
||||
with open(os.path.join(folder, "summary_log.txt"), 'a') as log_file:
|
||||
log_file.write(f"{datetime.now()}: {summary}\n")
|
Reference in New Issue
Block a user