Skip to content

Python scraper based on AI

removed unused files

Marco Vinciguerra47645d92ce49
diff --git a/manual deployment/autorequirements.py b/manual deployment/autorequirements.py
deleted file mode 100644
index 2bb7e1e8..00000000
--- a/manual deployment/autorequirements.py
+++ /dev/null
@@ -1,30 +0,0 @@
-import toml
-
-# Load the TOML file
-data = toml.load('pyproject.toml')
-
-# Get the dependencies
-dependencies = data['project']['dependencies']
-
-# Write the dependencies to a requirements.txt file
-with open('requirements.txt', 'w') as f:
- for dependency in dependencies:
- f.write(dependency + '\n')
-
-# Get the dev dependencies
-dev_dependencies = data['tool']['rye']['dev-dependencies']
-
-# Expand the optional dependencies
-optional_dependencies = data['project']['optional-dependencies']
-expanded_dev_dependencies = []
-for dependency in dev_dependencies:
- if dependency.startswith('-e file:.'):
- optional_dependency_name = dependency.split('.')[1][1:-1]
- expanded_dev_dependencies.extend(optional_dependencies[optional_dependency_name])
- else:
- expanded_dev_dependencies.append(dependency)
-
-# Write the expanded dev dependencies to a requirements-dev.txt file
-with open('requirements-dev.txt', 'w') as f:
- for dependency in expanded_dev_dependencies:
- f.write(dependency + '\n')
\ No newline at end of file
diff --git a/manual deployment/commit_and_push.sh b/manual deployment/commit_and_push.sh
deleted file mode 100755
index 95be163b..00000000
--- a/manual deployment/commit_and_push.sh
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/bash
-
-# Script: commit_and_push.sh
-# Description: This script performs pylint checks on specified Python files,
-# adds them to the Git repository, commits the changes with a provided message,
-# and pushes the changes to the remote repository.
-
-# Usage: ./commit_and_push.sh <commit_message>
-# <commit_message>: The message to be used for the Git commit.
-# The commit message should be under ""
-# If it is the first time you have to do chmod +x commit_and_push.sh
-
-# Check if an argument is provided
-if [ $# -eq 0 ]; then
- echo "Usage: $0 <commit_message>"
- exit 1
-fi
-
-cd ..
-# Extract the commit message from the argument
-commit_message="$1"
-
-# Run Pylint on the specified Python files
-pylint pylint scrapegraphai/**/*.py scrapegraphai/*.py tests/*.py
-
-#Make the pull
-git pull
-
-# Add the modified files to the Git repository
-git add .
-
-# Commit the changes with the provided message
-git commit -m "$commit_message"
-
-# Push the changes to the remote repository
-git push
diff --git a/manual deployment/commit_and_push_with_tests.sh b/manual deployment/commit_and_push_with_tests.sh
deleted file mode 100755
index d97fe67f..00000000
--- a/manual deployment/commit_and_push_with_tests.sh
+++ /dev/null
@@ -1,36 +0,0 @@
-if [ $# -eq 0 ]; then
- echo "Usage: $0 <commit_message>"
- exit 1
-fi
-
-cd ..
-
-# Extract the commit message from the argument
-commit_message="$1"
-
-# Run Pylint on the specified Python files
-pylint pylint scrapegraphai/**/*.py scrapegraphai/*.py tests/**/*.py
-
-cd tests
-
-poetry install
-
-# Run pytest
-if ! pytest; then
- echo "Pytest failed. Aborting commit and push."
- exit 1
-fi
-
-cd ..
-
-# Make the pull
-git pull
-
-# Add the modified files to the Git repository
-git add .
-
-# Commit the changes with the provided message
-git commit -m "$commit_message"
-
-# Push the changes to the remote repository
-git push
diff --git a/manual deployment/deploy_on_pip.sh b/manual deployment/deploy_on_pip.sh
deleted file mode 100755
index 08a92119..00000000
--- a/manual deployment/deploy_on_pip.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/bash
-cd ..
-
-rye self update
-
-rye pin 3.10
-
-# Install dependencies using Poetry
-rye sync
-
-# Build the project
-rye build
-
-# Publish the project to PyPI
-rye publish
diff --git a/manual deployment/installation.sh b/manual deployment/installation.sh
deleted file mode 100644
index c9c5d00b..00000000
--- a/manual deployment/installation.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-
-rye pin 3.10
-
-# Install dependencies using Poetry
-rye sync
-
-# Build the project
-rye build
\ No newline at end of file
diff --git a/scrapegraphai/builders/__init__.py b/scrapegraphai/builders/__init__.py
index 03fd2d1a..98520fcb 100644
--- a/scrapegraphai/builders/__init__.py
+++ b/scrapegraphai/builders/__init__.py
@@ -1,5 +1,5 @@
"""
- __init__.py file for builders folder
+__init__.py file for builders folder
"""
from .graph_builder import GraphBuilder
diff --git a/scrapegraphai/builders/graph_builder.py b/scrapegraphai/builders/graph_builder.py
index feb52ee3..e63b040b 100644
--- a/scrapegraphai/builders/graph_builder.py
+++ b/scrapegraphai/builders/graph_builder.py
@@ -6,7 +6,6 @@ from langchain.chains import create_extraction_chain
from langchain_community.chat_models import ErnieBotChat
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_openai import ChatOpenAI
-
from ..helpers import nodes_metadata, graph_schema
class GraphBuilder:
diff --git a/scrapegraphai/helpers/__init__.py b/scrapegraphai/helpers/__init__.py
index 0b586a81..97f0e5d5 100644
--- a/scrapegraphai/helpers/__init__.py
+++ b/scrapegraphai/helpers/__init__.py
@@ -1,7 +1,6 @@
"""
__init__.py for the helpers folder
"""
-
from .nodes_metadata import nodes_metadata
from .schemas import graph_schema
from .models_tokens import models_tokens
diff --git a/scrapegraphai/integrations/burr_bridge.py b/scrapegraphai/integrations/burr_bridge.py
index 9e186922..f7b4cd53 100644
--- a/scrapegraphai/integrations/burr_bridge.py
+++ b/scrapegraphai/integrations/burr_bridge.py
@@ -2,7 +2,6 @@
Bridge class to integrate Burr into ScrapeGraphAI graphs
[Burr](https://github.com/DAGWorks-Inc/burr)
"""
-
import re
import uuid
from hashlib import md5
diff --git a/scrapegraphai/nodes/fetch_node_level_k.py b/scrapegraphai/nodes/fetch_node_level_k.py
index d321b33c..0f772edf 100644
--- a/scrapegraphai/nodes/fetch_node_level_k.py
+++ b/scrapegraphai/nodes/fetch_node_level_k.py
@@ -1,11 +1,12 @@
+"""
+fetch_node_level_k module
+"""
from typing import List, Optional
-from .base_node import BaseNode
-from ..docloaders import ChromiumLoader
-from ..utils.cleanup_html import cleanup_html
-from ..utils.convert_to_md import convert_to_md
+from urllib.parse import urljoin
from langchain_core.documents import Document
from bs4 import BeautifulSoup
-from urllib.parse import quote, urljoin
+from .base_node import BaseNode
+from ..docloaders import ChromiumLoader
class FetchNodeLevelK(BaseNode):
"""
@@ -102,7 +103,7 @@ class FetchNodeLevelK(BaseNode):
Optional[str]: The fetched HTML content or None if fetching failed.
"""
self.logger.info(f"--- (Fetching HTML from: {source}) ---")
-
+
if self.browser_base is not None:
try:
from ..docloaders.browser_base import browser_base_fetch
@@ -110,9 +111,10 @@ class FetchNodeLevelK(BaseNode):
raise ImportError("""The browserbase module is not installed.
Please install it using `pip install browserbase`.""")
- data = browser_base_fetch(self.browser_base.get("api_key"),
+ data = browser_base_fetch(self.browser_base.get("api_key"),
self.browser_base.get("project_id"), [source])
- document = [Document(page_content=content, metadata={"source": source}) for content in data]
+ document = [Document(page_content=content,
+ metadata={"source": source}) for content in data]
else:
loader = ChromiumLoader([source], headless=self.headless, **loader_kwargs)
document = loader.load()
@@ -179,7 +181,8 @@ class FetchNodeLevelK(BaseNode):
full_links = self.get_full_links(source, links)
for link in full_links:
- if not any(d.get('source', '') == link for d in documents) and not any(d.get('source', '') == link for d in new_documents):
+ if not any(d.get('source', '') == link for d in documents) \
+ and not any(d.get('source', '') == link for d in new_documents):
new_documents.append({"source": link})
documents.extend(new_documents)
@@ -208,7 +211,8 @@ class FetchNodeLevelK(BaseNode):
if current_depth < depth:
new_links = self.extract_links(link_content)
- content_dict.update(self.process_links(full_link, new_links, loader_kwargs, depth, current_depth + 1))
+ content_dict.update(self.process_links(full_link, new_links,
+ loader_kwargs, depth, current_depth + 1))
else:
self.logger.warning(f"Failed to fetch content for {full_link}")
return content_dict
diff --git a/scrapegraphai/nodes/generate_answer_omni_node.py b/scrapegraphai/nodes/generate_answer_omni_node.py
index 403240dd..b1301c99 100644
--- a/scrapegraphai/nodes/generate_answer_omni_node.py
+++ b/scrapegraphai/nodes/generate_answer_omni_node.py
@@ -71,10 +71,8 @@ class GenerateAnswerOmniNode(BaseNode):
self.logger.info(f"--- Executing {self.node_name} Node ---")
- # Interpret input keys based on the provided input expression
input_keys = self.get_input_keys(state)
- # Fetching data from the state based on the input keys
input_data = [state[key] for key in input_keys]
user_prompt = input_data[0]
@@ -85,7 +83,7 @@ class GenerateAnswerOmniNode(BaseNode):
if isinstance(self.llm_model, (ChatOpenAI, ChatMistralAI)):
self.llm_model = self.llm_model.with_structured_output(
- schema = self.node_config["schema"]) # json schema works only on specific models
+ schema = self.node_config["schema"])
output_parser = get_structured_output_parser(self.node_config["schema"])
format_instructions = "NA"
@@ -106,8 +104,6 @@ class GenerateAnswerOmniNode(BaseNode):
TEMPLATE_CHUNKS_OMNI_prompt = self.additional_info + TEMPLATE_CHUNKS_OMNI_prompt
TEMPLATE_MERGE_OMNI_prompt = self.additional_info + TEMPLATE_MERGE_OMNI_prompt
-
-
chains_dict = {}
if len(doc) == 1:
prompt = PromptTemplate(
@@ -139,7 +135,6 @@ class GenerateAnswerOmniNode(BaseNode):
},
)
- # Dynamically name the chains based on their index
chain_name = f"chunk{i+1}"
chains_dict[chain_name] = prompt | self.llm_model | output_parser
diff --git a/scrapegraphai/nodes/generate_scraper_node.py b/scrapegraphai/nodes/generate_scraper_node.py
index 93ad9cf3..8868d710 100644
--- a/scrapegraphai/nodes/generate_scraper_node.py
+++ b/scrapegraphai/nodes/generate_scraper_node.py
@@ -27,7 +27,6 @@ class GenerateScraperNode(BaseNode):
node_name (str): The unique identifier name for the node, defaulting to "GenerateScraper".
"""
-
def __init__(
self,
input: str,
diff --git a/scrapegraphai/nodes/search_node_with_context.py b/scrapegraphai/nodes/search_node_with_context.py
index 5a21010c..8a3d9923 100644
--- a/scrapegraphai/nodes/search_node_with_context.py
+++ b/scrapegraphai/nodes/search_node_with_context.py
@@ -23,7 +23,8 @@ class SearchLinksWithContext(BaseNode):
input (str): Boolean expression defining the input keys needed from the state.
output (List[str]): List of output keys to be updated in the state.
node_config (dict): Additional configuration for the node.
- node_name (str): The unique identifier name for the node, defaulting to "SearchLinksWithContext".
+ node_name (str): The unique identifier name for the node,
+ defaulting to "SearchLinksWithContext".
"""
def __init__(
diff --git a/scrapegraphai/prompts/merge_generated_scripts_prompts.py b/scrapegraphai/prompts/merge_generated_scripts_prompts.py
index 720284cc..96925990 100644
--- a/scrapegraphai/prompts/merge_generated_scripts_prompts.py
+++ b/scrapegraphai/prompts/merge_generated_scripts_prompts.py
@@ -1,6 +1,7 @@
"""
merge_generated_scripts_prompts module
"""
+
TEMPLATE_MERGE_SCRIPTS_PROMPT = """
You are a python expert in web scraping and you have just generated multiple scripts to scrape different URLs.\n
The scripts are generated based on a user question and the content of the websites.\n
diff --git a/scrapegraphai/telemetry/telemetry.py b/scrapegraphai/telemetry/telemetry.py
index 61af900c..26f30674 100644
--- a/scrapegraphai/telemetry/telemetry.py
+++ b/scrapegraphai/telemetry/telemetry.py
@@ -34,10 +34,8 @@ API_KEY = "phc_orsfU4aHhtpTSLVcUE2hdUkQDLM4OEQZndKGFBKMEtn"
TIMEOUT = 2
DEFAULT_CONFIG_LOCATION = os.path.expanduser("~/.scrapegraphai.conf")
-
logger = logging.getLogger(__name__)
-
def _load_config(config_location: str) -> configparser.ConfigParser:
config = configparser.ConfigParser()
try:
@@ -58,7 +56,6 @@ def _load_config(config_location: str) -> configparser.ConfigParser:
pass
return config
-
def _check_config_and_environ_for_telemetry_flag(
telemetry_default: bool, config_obj: configparser.ConfigParser
) -> bool:
diff --git a/scrapegraphai/utils/code_error_analysis.py b/scrapegraphai/utils/code_error_analysis.py
index 77c8efdf..0acc8b3e 100644
--- a/scrapegraphai/utils/code_error_analysis.py
+++ b/scrapegraphai/utils/code_error_analysis.py
@@ -3,11 +3,13 @@ This module contains the functions that generate prompts for various types of co
Functions:
- syntax_focused_analysis: Focuses on syntax-related errors in the generated code.
-- execution_focused_analysis: Focuses on execution-related errors, including generated code and HTML analysis.
-- validation_focused_analysis: Focuses on validation-related errors, considering JSON schema and execution result.
-- semantic_focused_analysis: Focuses on semantic differences in generated code based on a comparison result.
+- execution_focused_analysis: Focuses on execution-related errors,
+including generated code and HTML analysis.
+- validation_focused_analysis: Focuses on validation-related errors,
+considering JSON schema and execution result.
+- semantic_focused_analysis: Focuses on semantic differences in
+generated code based on a comparison result.
"""
-
from typing import Any, Dict
import json
from langchain.prompts import PromptTemplate
@@ -63,7 +65,8 @@ def validation_focused_analysis(state: dict, llm_model) -> str:
Analyzes the validation errors in the generated code based on a JSON schema.
Args:
- state (dict): Contains the 'generated_code', 'errors', 'json_schema', and 'execution_result'.
+ state (dict): Contains the 'generated_code', 'errors',
+ 'json_schema', and 'execution_result'.
llm_model: The language model used for generating the analysis.
Returns:
diff --git a/scrapegraphai/utils/code_error_correction.py b/scrapegraphai/utils/code_error_correction.py
index 98908360..a5119b24 100644
--- a/scrapegraphai/utils/code_error_correction.py
+++ b/scrapegraphai/utils/code_error_correction.py
@@ -9,7 +9,6 @@ validation error analysis, considering JSON schema.
- semantic_focused_code_generation: Generates corrected code based on semantic error analysis,
comparing generated and reference results.
"""
-
import json
from langchain.prompts import PromptTemplate
from langchain_core.output_parsers import StrOutputParser
diff --git a/scrapegraphai/utils/copy.py b/scrapegraphai/utils/copy.py
index 5e018f8b..a35370ab 100644
--- a/scrapegraphai/utils/copy.py
+++ b/scrapegraphai/utils/copy.py
@@ -4,7 +4,6 @@ copy module
import copy
from typing import Any
-
class DeepCopyError(Exception):
"""
Custom exception raised when an object cannot be deep-copied.
diff --git a/scrapegraphai/utils/dict_content_compare.py b/scrapegraphai/utils/dict_content_compare.py
index 5ab4be41..8c1d2511 100644
--- a/scrapegraphai/utils/dict_content_compare.py
+++ b/scrapegraphai/utils/dict_content_compare.py
@@ -8,7 +8,6 @@ converting strings to lowercase and stripping whitespace.
converting strings to lowercase and stripping whitespace.
- are_content_equal: Compares two dictionaries for semantic equality after normalization.
"""
-
from typing import Any, Dict, List
def normalize_dict(d: Dict[str, Any]) -> Dict[str, Any]:
diff --git a/scrapegraphai/utils/model_costs.py b/scrapegraphai/utils/model_costs.py
index c6cce423..3cbc5ccd 100644
--- a/scrapegraphai/utils/model_costs.py
+++ b/scrapegraphai/utils/model_costs.py
@@ -1,11 +1,7 @@
-"""
-This file contains the cost of models per 1k tokens for input and output.
-The file is on a best effort basis and may not be up to date. Any contributions are welcome.
-"""
-
"""
Cost for 1k tokens in input
"""
+
MODEL_COST_PER_1K_TOKENS_INPUT = {
### MistralAI
# General Purpose
diff --git a/scrapegraphai/utils/proxy_rotation.py b/scrapegraphai/utils/proxy_rotation.py
index 9484b0ef..ede8cf33 100644
--- a/scrapegraphai/utils/proxy_rotation.py
+++ b/scrapegraphai/utils/proxy_rotation.py
@@ -10,7 +10,9 @@ from fp.errors import FreeProxyException
from fp.fp import FreeProxy
class ProxyBrokerCriteria(TypedDict, total=False):
- """proxy broker criteria"""
+ """
+ proxy broker criteria
+ """
anonymous: bool
countryset: Set[str]
@@ -20,7 +22,9 @@ class ProxyBrokerCriteria(TypedDict, total=False):
class ProxySettings(TypedDict, total=False):
- """proxy settings"""
+ """
+ proxy settings
+ """
server: str
bypass: str
@@ -29,7 +33,9 @@ class ProxySettings(TypedDict, total=False):
class Proxy(ProxySettings):
- """proxy server information"""
+ """
+ proxy server information
+ """
criteria: ProxyBrokerCriteria
diff --git a/scrapegraphai/utils/split_text_into_chunks.py b/scrapegraphai/utils/split_text_into_chunks.py
index 5584bf0b..f472d24c 100644
--- a/scrapegraphai/utils/split_text_into_chunks.py
+++ b/scrapegraphai/utils/split_text_into_chunks.py
@@ -31,7 +31,7 @@ def split_text_into_chunks(text: str, chunk_size: int,
memoize=False)
return chunks
- else:
+ else:
tokens = num_tokens_calculus(text, model)
if tokens <= chunk_size:
diff --git a/scrapegraphai/utils/sys_dynamic_import.py b/scrapegraphai/utils/sys_dynamic_import.py
index aa45a9b1..b420bcc4 100644
--- a/scrapegraphai/utils/sys_dynamic_import.py
+++ b/scrapegraphai/utils/sys_dynamic_import.py
@@ -10,7 +10,8 @@ if typing.TYPE_CHECKING:
import types
def srcfile_import(modpath: str, modname: str) -> "types.ModuleType":
- """imports a python module from its srcfile
+ """
+ imports a python module from its srcfile
Args:
modpath: The srcfile absolute path
@@ -42,7 +43,8 @@ def srcfile_import(modpath: str, modname: str) -> "types.ModuleType":
def dynamic_import(modname: str, message: str = "") -> None:
- """imports a python module at runtime
+ """
+ imports a python module at runtime
Args:
modname: The module name in the scope