File size: 1,334 Bytes
9c400b9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
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
|