Skip to content

Commit

Permalink
add search images
Browse files Browse the repository at this point in the history
  • Loading branch information
Qewertyy committed Dec 22, 2023
1 parent d5538a5 commit cda7d1a
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 3 deletions.
10 changes: 10 additions & 0 deletions examples/async_search_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from lexica import AsyncClient
import asyncio

async def main(query: str) -> dict:
client = AsyncClient()
response = await client.SearchImages(query)
return response

if __name__ == "__main__":
print(asyncio.run(main("akeno himejima")))
9 changes: 9 additions & 0 deletions examples/search_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from lexica import Client

def main(query: str) -> dict:
client = Client()
response = client.SearchImages(query)
return response

if __name__ == "__main__":
print(main("akeno himejima"))
28 changes: 27 additions & 1 deletion lexica/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def getImages(self,task_id:str,request_id:str) -> dict:
)
return resp

def ImageReverse(self, engine: str,imageUrl: str) -> dict:
def ImageReverse(self, imageUrl: str,engine: str="goole") -> dict:
"""
Reverse search an image
Example:
Expand Down Expand Up @@ -230,4 +230,30 @@ def MediaDownloaders(self,platform: str,url:str):
method='POST',
params={"url": url}
)
return resp

def SearchImages(self,query: str, engine: str="google") -> dict:
"""
Search for images
Example:
>>> client = Client()
>>> response = client.SearchImages(query)
>>> print(response)
Args:
query (str): query to perform the search.
Returns:
dict: Answer from the API in the following format:
{
"message": str,
"content": [],
"code": int
}
"""
resp = self._request(
url=f'{self.url}/image-search/{engine}',
method='POST',
params={"query": query}
)
return resp
28 changes: 27 additions & 1 deletion lexica/core_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ async def getImages(self,task_id:str,request_id:str) -> dict:
)
return resp

async def ImageReverse(self, engine: str,imageUrl: str) -> dict:
async def ImageReverse(self, imageUrl: str,engine: str="google") -> dict:
"""
Reverse search an image
Example:
Expand Down Expand Up @@ -242,3 +242,29 @@ async def MediaDownloaders(self,platform: str,url:str) -> dict:
params={'url': url}
)
return resp

async def SearchImages(self,query: str, engine: str="google") -> dict:
"""
Search for images
Example:
>>> client = AsyncClient()
>>> response = await client.SearchImages(query)
>>> print(response)
Args:
query (str): query to perform the search.
Returns:
dict: Answer from the API in the following format:
{
"message": str,
"content": [],
"code": int
}
"""
resp = await self._request(
url=f'{self.url}/image-search/{engine}',
method='POST',
params={'query': query}
)
return resp
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def get_long_description():

setup(
name="lexica-api",
version="1.4.8",
version="1.4.9",
author="Qewertyy",
author_email="[email protected]",
description="The python package for api.qewertyy.me",
Expand Down

0 comments on commit cda7d1a

Please sign in to comment.