~nova/resp_search

2d73039718e85f477f1194396a3295920b3b09a8 — Novalinium 2 months ago
Initial commit
5 files changed, 82 insertions(+), 0 deletions(-)

A .gitmodules
A main.py
A requirements.txt
A resp
A test_acm.py
A  => .gitmodules +3 -0
@@ 1,3 @@
[submodule "resp"]
	path = resp
	url = https://github.com/monk1337/resp

A  => main.py +64 -0
@@ 1,64 @@
# from resp.apis.serp_api import Serp (seems expensive so no)
# from resp.apis.cnnp import connected_papers add selenium
from resp.apis.semantic_s import Semantic_Scholar
from resp.apis.acm_api import ACM
from resp.apis.arxiv_api import Arxiv
from starlette.applications import Starlette
from starlette.responses import JSONResponse, HTMLResponse, PlainTextResponse
from starlette.routing import Route
from starlette.routing import Mount
from starlette.staticfiles import StaticFiles

from datetime import datetime
from asyncio import gather


# from resp.resp import Resp Serps

ap = Arxiv()
acm = ACM()
sc = Semantic_Scholar()


async def homepage(request):
    q = request.query_params.get("q")
    if q:
        searches = await gather(
            ap.arxiv(q, max_pages=1),
            acm.acm(q, max_pages=1, max_year=datetime.now().year),
        )
        search_block = "<hr /><h3>Arxiv</h3><ul>"
        for _, search in searches[0].iterrows():
            link = search["link"]
            title = search["title"]
            search_block += f'<li><a href="{link}" target="_blank">{title}</a>'
        search_block += "</ul>"
        search_block += f"<h3>ACM Results</h3><pre>{searches[1]}</pre>"
    else:
        search_block = ""
        q = "Query me! I'm friendly!"
    return HTMLResponse(
        f"""
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>My Cool Search Engine</title>
</head>
<body>
<form>
<label>Search: <input type="text" name="q" autofocus value="{q}" /></label>
<input type="submit" value="Do it!"/>
</form>
{search_block}
<script type="text/javascript" src="/js/popups.js"></script>
</html>
"""
    )


routes = [
    Route("/", endpoint=homepage),
    Mount("/js", app=StaticFiles(directory="public/js"), name="js"),
]

app = Starlette(debug=True, routes=routes)

A  => requirements.txt +4 -0
@@ 1,4 @@
starlette
httpx
bs4
pandas

A  => resp +1 -0
@@ 1,1 @@
Subproject commit 5cbce3162aec26fdfbc0ad0fbd26bbff58d7d755

A  => test_acm.py +10 -0
@@ 1,10 @@
from resp.apis.acm_api import ACM
from datetime import datetime
import trio


async def main():
    print(await ACM().acm("test", max_pages=1, max_year=datetime.now().year))


trio.run(main)