Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/0.3.2/add proxy support #38

Merged
merged 3 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[tool.poetry]
name = "webtranspose"
version = "0.3.1"
version = "0.3.2"
description = "Reliable APIs for the website data"
authors = ["Mike Gee <[email protected]>"]

Expand Down
2 changes: 1 addition & 1 deletion src/webtranspose/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(
chunk_size (int, optional): The size of each chunk of text to process. Defaults to 2500.
overlap_size (int, optional): The size of the overlap between chunks. Defaults to 100.
"""
self.api_key = os.environ["OPENAI_API_KEY"]
self.api_key = os.environ.get("OPENAI_API_KEY")
self.encoding = tiktoken.encoding_for_model("gpt-3.5-turbo")
self.chunk_size = chunk_size
self.overlap_size = overlap_size
Expand Down
8 changes: 8 additions & 0 deletions src/webtranspose/scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(
verbose: bool = False,
scraper: OpenAIScraper = None,
api_key: str = None,
proxy: str = None,
_created: bool = False,
):
"""
Expand All @@ -34,6 +35,7 @@ def __init__(
verbose (bool, optional): Whether to print verbose output. Defaults to False.
scraper (OpenAIScraper, optional): The scraper object. Defaults to None.
api_key (str, optional): The API key. Defaults to None.
proxy (str, optional): The proxy. Defaults to None.
_created (bool, optional): Whether the scraper has been created. Defaults to False.
"""
self.api_key = api_key
Expand All @@ -48,6 +50,7 @@ def __init__(
self.scraper = scraper
self.render_js = render_js
self.scraper_id = scraper_id
self.proxy = proxy
if self.scraper is None:
self.scraper = OpenAIScraper()
if self.scraper_id is None:
Expand Down Expand Up @@ -107,6 +110,7 @@ def create_scraper_api(self):
"name": self.name,
"schema": self.schema,
"render_js": self.render_js,
"proxy": self.proxy,
}
out_json = run_webt_api(
create_json,
Expand Down Expand Up @@ -156,6 +160,7 @@ def scrape(self, url=None, html=None, timeout=30):
"scraper_id": self.scraper_id,
"url": url,
"html": html,
"proxy": self.proxy,
}
out_json = run_webt_api(
scrape_json,
Expand All @@ -178,6 +183,7 @@ def status(self):
"verbose": self.verbose,
"render_js": self.render_js,
"schema": self.schema,
"proxy": self.proxy,
}
else:
get_json = {
Expand All @@ -195,6 +201,7 @@ def status(self):
"verbose": self.verbose,
"render_js": scraper["render_js"],
"schema": scraper["schema"],
"proxy": scraper["proxy"]
}


Expand Down Expand Up @@ -231,6 +238,7 @@ def get_scraper(scraper_id, api_key: str = None):
schema=scraper["schema"],
render_js=scraper["render_js"],
api_key=api_key,
proxy=scraper['proxy'],
_created=True,
)

Expand Down
Loading