app / src /xbt-core.py
lemdaddy's picture
first commit
9c400b9
raw
history blame
1.33 kB
import os
import httpx
import urllib.parse
from typing import Self
from pyjsonq import JsonQ
from dotenv import load_dotenv
load_dotenv()
JINA_SEARCH_BASE_ENDPOINT = "r.jina.ai"
JINA_READER_BASE_ENDPOINT = "s.jina.ai"
class XBTCore:
def __init__(self) -> None:
self.value = 0
self.JINA_SEARCH_BASE_ENDPOINT = "s.jina.ai"
self.JINA_READER_BASE_ENDPOINT = "r.jina.ai"
def search_web_with_jina(self, search_query: str=False) -> Self:
url = self.JINA_SEARCH_BASE_ENDPOINT
encoded_search_query = urllib.parse.quote(search_query)
try:
with httpx.Client() as client:
response = client.get(f"{url}/{encoded_search_query}")
response.raise_for_status()
return response.json()
except httpx.HTTPError as e:
print(f"An error occurred: {e}")
return None
def read_website_with_jina(self, website_url: str=False) -> Self:
url = self.JINA_READER_BASE_ENDPOINT
try:
with httpx.Client() as client:
response = client.get(f"{url}/{website_url}")
response.raise_for_status()
return response.json()
except httpx.HTTPError as e:
print(f"An error occurred: {e}")
return None