Skip to content

Python scraper based on AI

add: readthedocs structure

PeriniM787fea0e78fe
diff --git a/.gitignore b/.gitignore
index 2cd267db..7a9e89dc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,5 +17,6 @@ MANIFEST
docs/build/
docs/source/_templates/
+docs/source/_static/
.env
venv/
diff --git a/MANIFEST.in b/MANIFEST.in
deleted file mode 100644
index c269e040..00000000
--- a/MANIFEST.in
+++ /dev/null
@@ -1,34 +0,0 @@
-# Include the license file
-include LICENSE
-
-# Include the readme and other markdown files
-include README.md
-include CONTRIBUTING.md
-
-# Include the requirements file
-include requirements.txt
-
-# Include the setup configuration
-include setup.py
-
-# Include the documentation files
-recursive-include docs *.md
-recursive-include docs *.rst
-
-# Include the YAML configuration for Read the Docs
-include readthedocs.yml
-
-# Include Python source files from the project's subpackages
-recursive-include utils *.py
-recursive-include examples *.py
-recursive-include tests *.py
-
-# If you want to exclude specific files or patterns, use the 'global-exclude' directive
-# global-exclude *.pyc
-# global-exclude __pycache__/*
-
-# Exclude all bytecode compiled files
-global-exclude *.py[cod]
-
-# Exclude OS generated files like .DS_Store
-global-exclude .DS_Store
\ No newline at end of file
diff --git a/README.md b/README.md
index 2f18dbc6..3f359169 100644
--- a/README.md
+++ b/README.md
@@ -28,13 +28,13 @@ Follow the following steps:
5. Now you can access to [https://platform.openai.com/docs/overview](https://platform.openai.com/docs/overview)
6. Create a new API key and copy it
- <img src="docs/generate_api_key/step_1.png" alt="Step 1 Screenshot" width="60%"/>
+ <img src="docs/assets/apikey_1.png" alt="Step 1 Screenshot" width="70%"/>
- <img src="docs/generate_api_key/step_2.png" alt="Step 2 Screenshot" width="60%"/>
+ <img src="docs/assets/apikey_2.png" alt="Step 2 Screenshot" width="70%"/>
- <img src="docs/generate_api_key/step_3.png" alt="Step 3 Screenshot" width="60%"/>
+ <img src="docs/assets/apikey_3.png" alt="Step 3 Screenshot" width="70%"/>
- <img src="docs/generate_api_key/step_4.png" alt="Step 4 Screenshot" width="60%"/>
+ <img src="docs/assets/apikey_4.png" alt="Step 4 Screenshot" width="70%"/>
7. Create a .env file inside the main and paste the API key
@@ -181,4 +181,4 @@ The oputput format is a dict and its the following:
Developed by
-![logo-removebg-preview.png](docs/logo_vincios.png)
+![logo-removebg-preview.png](docs/assets/logo_vincios.png)
diff --git a/aaa/prova.py b/aaa/prova.py
new file mode 100644
index 00000000..22171a0e
--- /dev/null
+++ b/aaa/prova.py
@@ -0,0 +1,18 @@
+from amazscraper.class_generator import Generator
+from amazscraper.getter import get_function, scraper
+
+values = [
+ {
+ "title": "title",
+ "type": "str",
+ "description": "Title of the items"
+ }
+]
+
+if __name__ == "__main__":
+
+ generator_instance = Generator(values, 0, "gpt-3.5-turbo")
+
+ res = generator_instance.invocation(scraper("https://www.mockupworld.co", 4197))
+
+ print(res)
\ No newline at end of file
diff --git a/__init__.py b/amazscraper/__init__.py
similarity index 100%
rename from __init__.py
rename to amazscraper/__init__.py
diff --git a/utils/class_creator.py b/amazscraper/class_creator.py
similarity index 100%
rename from utils/class_creator.py
rename to amazscraper/class_creator.py
diff --git a/utils/class_generator.py b/amazscraper/class_generator.py
similarity index 100%
rename from utils/class_generator.py
rename to amazscraper/class_generator.py
diff --git a/utils/getter.py b/amazscraper/getter.py
similarity index 100%
rename from utils/getter.py
rename to amazscraper/getter.py
diff --git a/utils/pydantic_class.py b/amazscraper/pydantic_class.py
similarity index 100%
rename from utils/pydantic_class.py
rename to amazscraper/pydantic_class.py
diff --git a/docs/Makefile b/docs/Makefile
new file mode 100644
index 00000000..d0c3cbf1
--- /dev/null
+++ b/docs/Makefile
@@ -0,0 +1,20 @@
+# Minimal makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line, and also
+# from the environment for the first two.
+SPHINXOPTS ?=
+SPHINXBUILD ?= sphinx-build
+SOURCEDIR = source
+BUILDDIR = build
+
+# Put it first so that "make" without argument is like "make help".
+help:
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
+
+.PHONY: help Makefile
+
+# Catch-all target: route all unknown targets to Sphinx using the new
+# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
+%: Makefile
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
diff --git a/docs/generate_api_key/step_1.png b/docs/assets/apikey_1.png
similarity index 100%
rename from docs/generate_api_key/step_1.png
rename to docs/assets/apikey_1.png
diff --git a/docs/generate_api_key/step_2.png b/docs/assets/apikey_2.png
similarity index 100%
rename from docs/generate_api_key/step_2.png
rename to docs/assets/apikey_2.png
diff --git a/docs/generate_api_key/step_3.png b/docs/assets/apikey_3.png
similarity index 100%
rename from docs/generate_api_key/step_3.png
rename to docs/assets/apikey_3.png
diff --git a/docs/generate_api_key/step_4.png b/docs/assets/apikey_4.png
similarity index 100%
rename from docs/generate_api_key/step_4.png
rename to docs/assets/apikey_4.png
diff --git a/docs/logo_vincios.png b/docs/assets/logo_vincios.png
similarity index 100%
rename from docs/logo_vincios.png
rename to docs/assets/logo_vincios.png
diff --git a/docs/make.bat b/docs/make.bat
new file mode 100644
index 00000000..dc1312ab
--- /dev/null
+++ b/docs/make.bat
@@ -0,0 +1,35 @@
+@ECHO OFF
+
+pushd %~dp0
+
+REM Command file for Sphinx documentation
+
+if "%SPHINXBUILD%" == "" (
+ set SPHINXBUILD=sphinx-build
+)
+set SOURCEDIR=source
+set BUILDDIR=build
+
+%SPHINXBUILD% >NUL 2>NUL
+if errorlevel 9009 (
+ echo.
+ echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
+ echo.installed, then set the SPHINXBUILD environment variable to point
+ echo.to the full path of the 'sphinx-build' executable. Alternatively you
+ echo.may add the Sphinx directory to PATH.
+ echo.
+ echo.If you don't have Sphinx installed, grab it from
+ echo.https://www.sphinx-doc.org/
+ exit /b 1
+)
+
+if "%1" == "" goto help
+
+%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
+goto end
+
+:help
+%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
+
+:end
+popd
diff --git a/docs/source/conf.py b/docs/source/conf.py
new file mode 100644
index 00000000..ce2519c2
--- /dev/null
+++ b/docs/source/conf.py
@@ -0,0 +1,31 @@
+# Configuration file for the Sphinx documentation builder.
+#
+# For the full list of built-in configuration values, see the documentation:
+# https://www.sphinx-doc.org/en/master/usage/configuration.html
+
+# -- Project information -----------------------------------------------------
+# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
+
+# -- Path setup --------------------------------------------------------------
+
+import os, sys
+
+sys.path.insert(0, os.path.abspath('../../amazscraper'))
+
+project = 'amazscraper'
+copyright = '2024, Marco Vinciguerra'
+author = 'Marco Vinciguerra'
+
+# -- General configuration ---------------------------------------------------
+# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
+
+extensions = ['sphinx.ext.autodoc', 'sphinx.ext.napoleon']
+
+templates_path = ['_templates']
+exclude_patterns = []
+
+# -- Options for HTML output -------------------------------------------------
+# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
+
+html_theme = 'sphinx_rtd_theme'
+html_static_path = ['_static']
\ No newline at end of file
diff --git a/docs/source/getting_started/installation.rst b/docs/source/getting_started/installation.rst
new file mode 100644
index 00000000..ce916bb7
--- /dev/null
+++ b/docs/source/getting_started/installation.rst
@@ -0,0 +1,84 @@
+Installation
+------------
+
+In the following sections I will guide you through the installation process of the required components
+for this project.
+
+Prerequisites
+^^^^^^^^^^^^^
+
+- `Python 3.8+ <https://www.python.org/downloads/>`_
+- `Visual Studio Code <https://code.visualstudio.com/download>`_ or IDE of your choice
+
+External dependencies
+^^^^^^^^^^^^^^^^^^^^^
+
+Windows
++++++++
+
+Insert external dependencies for Windows if there are any.
+
+Linux
+++++++
+
+You don't need to install any external dependencies.
+
+Clone the repository
+^^^^^^^^^^^^^^^^^^^^
+
+.. code-block:: bash
+
+ git clone https://github.com/VinciGit00/AmazScraper
+ cd AmazScraper
+
+Create a virtual environment
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+It is recommended to create a virtual environment to install the dependencies in order to avoid conflicts with other projects.
+
+.. code-block:: bash
+
+ python -m venv venv
+ # python3 -m venv venv
+
+Activate the virtual environment
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+All the commands must be executed in the virtual environment. If you are not familiar with virtual environments, please read the `Python Virtual Environments: A Primer <https://realpython.com/python-virtual-environments-a-primer/>`_ article.
+
+To activate the virtual environment, run the following command:
+
+.. code-block:: bash
+
+ # Windows
+ .\venv\Scripts\activate
+ # Linux
+ source venv/bin/activate
+
+Install the dependencies
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+In the **requirements.txt** file you will find all the dependencies needed to run the code. To install them, run the following command:
+
+.. code-block:: bash
+
+ pip install -r requirements.txt
+ # pip3 install -r requirements.txt
+
+Test the installation
+^^^^^^^^^^^^^^^^^^^^^
+
+- Let's test if the installation was successful. Run the following command:
+
+ .. code-block:: bash
+
+ python some_example.py
+ # python3 .some_example.py
+
+- Let's test if the modules works. Run the following command:
+
+ .. code-block:: bash
+
+ python -m examples.values_scraping
+ # or
+ python -m examples.html_scraping
\ No newline at end of file
diff --git a/docs/source/index.rst b/docs/source/index.rst
new file mode 100644
index 00000000..7e5bce2a
--- /dev/null
+++ b/docs/source/index.rst
@@ -0,0 +1,31 @@
+.. amazscraper documentation master file, created by
+ sphinx-quickstart on Wed Jan 31 15:38:23 2024.
+ You can adapt this file completely to your liking, but it should at least
+ contain the root `toctree` directive.
+
+Welcome to amazscraper's documentation!
+=======================================
+
+Here you will find all the information you need to get started with the amazscraper project.
+The following sections will guide you through the installation process and the usage of the library.
+
+.. toctree::
+ :maxdepth: 2
+ :caption: Introduction
+
+ introduction/overview
+ introduction/contributing
+
+.. toctree::
+ :maxdepth: 2
+ :caption: Getting Started
+
+ getting_started/installation
+ modules/modules
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`
\ No newline at end of file
diff --git a/docs/source/introduction/contributing.rst b/docs/source/introduction/contributing.rst
new file mode 100644
index 00000000..0a2d9196
--- /dev/null
+++ b/docs/source/introduction/contributing.rst
@@ -0,0 +1,13 @@
+Contributing
+============
+
+Hey, you want to contribute? Awesome!
+Just fork the repo, make your changes, and send me a pull request.
+If you're not sure if it's a good idea, open an issue and we'll discuss it.
+
+Go and check out the `contributing guidelines <https://github.com/VinciGit00/AmazScraper/blob/main/CONTRIBUTING.md>`__ for more information.
+
+License
+=======
+This project is licensed under the Apache License, Version 2.0.
+See the `LICENSE <https://github.com/VinciGit00/AmazScraper/blob/main/LICENSE>`__ file for more details.
diff --git a/docs/source/introduction/overview.rst b/docs/source/introduction/overview.rst
new file mode 100644
index 00000000..488405e5
--- /dev/null
+++ b/docs/source/introduction/overview.rst
@@ -0,0 +1,10 @@
+Overview
+========
+
+This is an open source project aimed at developing a scraping library using LLM through Langchain.
+The goal is to be able to scrape data using natural language queries and store them in a structured format.
+
+.. image:: ../../assets/apikey_1.png
+ :align: center
+ :width: 400px
+ :alt: OpenAI Key
\ No newline at end of file
diff --git a/docs/source/modules/amazscraper.rst b/docs/source/modules/amazscraper.rst
new file mode 100644
index 00000000..a7f55456
--- /dev/null
+++ b/docs/source/modules/amazscraper.rst
@@ -0,0 +1,45 @@
+amazscraper package
+===================
+
+Submodules
+----------
+
+amazscraper.class\_creator module
+---------------------------------
+
+.. automodule:: amazscraper.class_creator
+ :members:
+ :undoc-members:
+ :show-inheritance:
+
+amazscraper.class\_generator module
+-----------------------------------
+
+.. automodule:: amazscraper.class_generator
+ :members:
+ :undoc-members:
+ :show-inheritance:
+
+amazscraper.getter module
+-------------------------
+
+.. automodule:: amazscraper.getter
+ :members:
+ :undoc-members:
+ :show-inheritance:
+
+amazscraper.pydantic\_class module
+----------------------------------
+
+.. automodule:: amazscraper.pydantic_class
+ :members:
+ :undoc-members:
+ :show-inheritance:
+
+Module contents
+---------------
+
+.. automodule:: amazscraper
+ :members:
+ :undoc-members:
+ :show-inheritance:
diff --git a/docs/source/modules/modules.rst b/docs/source/modules/modules.rst
new file mode 100644
index 00000000..ecd7499f
--- /dev/null
+++ b/docs/source/modules/modules.rst
@@ -0,0 +1,7 @@
+modules
+===========
+
+.. toctree::
+ :maxdepth: 4
+
+ amazscraper
diff --git a/examples/html_scraping.py b/examples/html_scraping.py
index 1e1efce2..61eb99e4 100644
--- a/examples/html_scraping.py
+++ b/examples/html_scraping.py
@@ -1,5 +1,5 @@
import sys
-from utils.class_generator import Generator
+from amazscraper.class_generator import Generator
values = [
{
diff --git a/examples/values_scraping.py b/examples/values_scraping.py
index e4a329b9..6559e22b 100644
--- a/examples/values_scraping.py
+++ b/examples/values_scraping.py
@@ -1,6 +1,6 @@
-from utils.class_generator import Generator
+from amazscraper.class_generator import Generator
-from utils.getter import get_function, scraper
+from amazscraper.getter import get_function, scraper
values = [
{
diff --git a/requirements.txt b/requirements.txt
index 2cfaf270..1735ae88 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -4,4 +4,9 @@ langchain_core==0.1.16
langchain_openai==0.0.5
python-dotenv==1.0.1
Requests==2.31.0
-pytest==8.0.0
\ No newline at end of file
+pytest==8.0.0
+
+wheel==0.42.0
+twine==4.0.2
+sphinx==7.1.2
+sphinx-rtd-theme==2.0.0
\ No newline at end of file
diff --git a/setup.py b/setup.py
index 8b549fea..17761856 100644
--- a/setup.py
+++ b/setup.py
@@ -1,24 +1,38 @@
+# Always prefer setuptools over distutils
from setuptools import setup, find_packages
-# Read in the requirements.txt file
-with open('requirements.txt') as f:
- requirements = f.read().splitlines()
-
setup(
name='amazscraper',
- version='1.0.0', # MAJOR.MINOR.PATCH
+ version='0.1.0', # MAJOR.MINOR.PATCH
description='A web scraping library using langchain',
+ long_description='A web scraping library using langchain but a longer description',
+ long_description_content_type='text/markdown',
+ url='https://amazscraper.readthedocs.io/',
author='Marco Vinciguerra',
author_email='[email protected]',
- packages=find_packages(),
- install_requires=requirements,
- # Include package data files from MANIFEST.in
- include_package_data=True,
license='Apache 2.0',
- # Additional classifiers to help users find the package
+ keywords='langchain, ai, artificial intelligence, gpt, machine learning, ml, nlp, natural language processing, openai, scraping, web scraping, web scraping library, web scraping tool, webscraping',
classifiers=[
- 'Programming Language :: Python :: 3',
+ 'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
+ 'Topic :: Software Development :: Scraping',
+ 'Programming Language :: Python :: 3',
+ 'Programming Language :: Python :: 3.6',
+ 'Programming Language :: Python :: 3.7',
+ 'Programming Language :: Python :: 3.8',
+ 'Programming Language :: Python :: 3.9',
'Operating System :: OS Independent',
],
+ packages = ['amazscraper'],
+ include_package_data=True,
+ # https://packaging.python.org/en/latest/discussions/install-requires-vs-requirements/
+ install_requires=[
+ 'beautifulsoup4',
+ 'langchain',
+ 'langchain_core',
+ 'langchain_openai',
+ 'python-dotenv',
+ 'Requests',
+ 'pytest',
+ ]
)
diff --git a/utils/__init__.py b/tests/__init__.py
similarity index 100%
rename from utils/__init__.py
rename to tests/__init__.py
diff --git a/tests/test_amaz_scraper.py b/tests/test_amaz_scraper.py
index a6f21675..fe9a1795 100644
--- a/tests/test_amaz_scraper.py
+++ b/tests/test_amaz_scraper.py
@@ -1,6 +1,6 @@
import pytest
-from utils.pydantic_class import _Response
-from utils.class_creator import create_class
+from amazscraper.pydantic_class import _Response
+from amazscraper.class_creator import create_class
from langchain_openai import ChatOpenAI
@pytest.fixture