Skip to content

Commit

Permalink
feat: refactoring of the folders
Browse files Browse the repository at this point in the history
  • Loading branch information
VinciGit00 committed Nov 4, 2024
1 parent db6cbd9 commit 908e67f
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 35 deletions.
2 changes: 1 addition & 1 deletion examples/credits_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import os
from dotenv import load_dotenv
from scrapegraphaiapisdk.credits import credits
from scrapegraph_py.credits import credits

# Load environment variables from a .env file
load_dotenv()
Expand Down
4 changes: 2 additions & 2 deletions examples/feedback_example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from dotenv import load_dotenv
from scrapegraphaiapisdk.credits import status
from scrapegraphaiapisdk.feedback import feedback
from scrapegraph_py.credits import status
from scrapegraph_py.feedback import feedback

# Load environment variables from .env file
load_dotenv()
Expand Down
2 changes: 1 addition & 1 deletion examples/scrape_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from scrapegraphaiapisdk.scrape import scrape
from scrapegraph_py.scrape import scrape
from dotenv import load_dotenv # Import load_dotenv
import os # Import os to access environment variables
import json # Import json for beautifying output
Expand Down
19 changes: 6 additions & 13 deletions examples/scrape_schema_example.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pydantic import BaseModel
from scrapegraphaiapisdk.scrape import scrape
from pydantic import BaseModel, Field
from scrapegraph_py.scrape import scrape
from dotenv import load_dotenv
import os

Expand All @@ -8,23 +8,16 @@

# Define a Pydantic schema
class CompanyInfoSchema(BaseModel):
company_name: str
description: str
main_products: list[str]
company_name: str = Field(description="The name of the company")
description: str = Field(description="A description of the company")
main_products: list[str] = Field(description="The main products of the company")

# Example usage
api_key = os.getenv("SCRAPEGRAPH_API_KEY")
url = "https://scrapegraphai.com/"
prompt = "What does the company do?"

# Create an instance of the schema with initial values
schema = CompanyInfoSchema(
company_name="Example Company",
description="An example company description.",
main_products=["Product1", "Product2"]
)

# Call the scrape function with the schema
result = scrape(api_key=api_key, url=url, prompt=prompt, schema=schema)
result = scrape(api_key=api_key, url=url, prompt=prompt, schema=CompanyInfoSchema)

print(result)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[project]
name = "scrapegraphaiapisdk"
name = "scrapegraph_py"
version = "0.0.1"
description = "library for extracting reference from documents"
authors = [
Expand Down
10 changes: 5 additions & 5 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ docutils==0.19
exceptiongroup==1.2.2
# via pytest
furo==2024.5.6
# via scrapegraphaiapisdk
# via scrapegraph-py
idna==3.10
# via requests
imagesize==1.4.1
Expand All @@ -54,7 +54,7 @@ platformdirs==4.3.6
pluggy==1.5.0
# via pytest
pydantic==2.9.2
# via scrapegraphaiapisdk
# via scrapegraph-py
pydantic-core==2.23.4
# via pydantic
pygments==2.18.0
Expand All @@ -65,17 +65,17 @@ pytest==8.0.0
# via pytest-mock
pytest-mock==3.14.0
python-dotenv==1.0.1
# via scrapegraphaiapisdk
# via scrapegraph-py
requests==2.32.3
# via scrapegraphaiapisdk
# via scrapegraph-py
# via sphinx
snowballstemmer==2.2.0
# via sphinx
soupsieve==2.6
# via beautifulsoup4
sphinx==6.0.0
# via furo
# via scrapegraphaiapisdk
# via scrapegraph-py
# via sphinx-basic-ng
sphinx-basic-ng==1.0.0b2
# via furo
Expand Down
6 changes: 3 additions & 3 deletions requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ charset-normalizer==3.4.0
idna==3.10
# via requests
pydantic==2.9.2
# via scrapegraphaiapisdk
# via scrapegraph-py
pydantic-core==2.23.4
# via pydantic
python-dotenv==1.0.1
# via scrapegraphaiapisdk
# via scrapegraph-py
requests==2.32.3
# via scrapegraphaiapisdk
# via scrapegraph-py
typing-extensions==4.12.2
# via pydantic
# via pydantic-core
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions tests/test_credits.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import unittest
from unittest.mock import patch
from scrapegraphaiapisdk.credits import credits
from scrapegraph_py.credits import credits

class TestCredits(unittest.TestCase):

@patch('scrapegraphaiapisdk.credits.requests.get')
@patch('scrapegraph_py.credits.requests.get')
def test_credits_success(self, mock_get):
mock_get.return_value.status_code = 200
mock_get.return_value.text = '{"credits": 100}'
response = credits("test_api_key")
self.assertEqual(response, '{"credits": 100}')

@patch('scrapegraphaiapisdk.credits.requests.get')
@patch('scrapegraph_py.credits.requests.get')
def test_credits_http_error(self, mock_get):
mock_get.side_effect = requests.exceptions.HTTPError
response = credits("test_api_key")
Expand Down
6 changes: 3 additions & 3 deletions tests/test_feedback.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import unittest
from unittest.mock import patch
from scrapegraphaiapisdk.feedback import feedback
from scrapegraph_py.feedback import feedback
import requests

class TestFeedback(unittest.TestCase):

@patch('scrapegraphaiapisdk.feedback.requests.post')
@patch('scrapegraph_py.feedback.requests.post')
def test_feedback_success(self, mock_post):
mock_post.return_value.status_code = 200
mock_post.return_value.text = '{"status": "success"}'
response = feedback("test_api_key", "3fa85f64-5717-4562-b3fc-2c963f66afa6", 5, "Great service!")
self.assertEqual(response, '{"status": "success"}')

@patch('scrapegraphaiapisdk.feedback.requests.post')
@patch('scrapegraph_py.feedback.requests.post')
def test_feedback_http_error(self, mock_post):
mock_post.side_effect = requests.exceptions.HTTPError
response = feedback("test_api_key", "3fa85f64-5717-4562-b3fc-2c963f66afa6", 5, "Great service!")
Expand Down
6 changes: 3 additions & 3 deletions tests/test_scrape.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import unittest
from unittest.mock import patch
from scrapegraphaiapisdk.scrape import scrape
from scrapegraph_py.scrape import scrape

class TestScrape(unittest.TestCase):

@patch('scrapegraphaiapisdk.scrape.requests.post')
@patch('scrapegraph_py.scrape.requests.post')
def test_scrape_success(self, mock_post):
mock_post.return_value.status_code = 200
mock_post.return_value.text = '{"data": "extracted data"}'
response = scrape("test_api_key", "http://example.com", "Extract data")
self.assertEqual(response, '{"data": "extracted data"}')

@patch('scrapegraphaiapisdk.scrape.requests.post')
@patch('scrapegraph_py.scrape.requests.post')
def test_scrape_http_error(self, mock_post):
mock_post.side_effect = requests.exceptions.HTTPError
response = scrape("test_api_key", "http://example.com", "Extract data")
Expand Down

0 comments on commit 908e67f

Please sign in to comment.