page=1
async def get_data(textbox):
global page
from js import fetch
response = await fetch("https://b.proovs.eu/q?q="+textbox+'&p='+str(page))
text = await response.text()
#print(text)
import json
data = json.loads(text)
from js import document
result_div = document.getElementById("result")
result_div.innerHTML = ""
for item in data[0]:
print(item['link'])
div = document.createElement("div")
div.className = "result_item"
a = document.createElement("a")
a.href = item["link"]
a.innerText = item["snippet"]
a.target = "_blank" # open in new tab
div.appendChild(a)
result_div.appendChild(div)
from pyscript import when, display
@when("click", "#btn")
def click_handler(event):
global page
page=1
from js import document
textbox = document.getElementById("search_box").value
if len(textbox)>0:
import asyncio
asyncio.create_task(get_data(textbox))
@when("click", "#prev")
def click_handler(event):
global page
if page>1:
page-=1
from js import document
where = document.getElementById("where")
where.innerHTML=str(page)
from js import document
textbox = document.getElementById("search_box").value
import asyncio
asyncio.create_task(get_data(textbox))
@when("click", "#next")
def click_handler(event):
global page
if page<50:
page+=1
from js import document
where = document.getElementById("where")
where.innerHTML=str(page)
from js import document
textbox = document.getElementById("search_box").value
import asyncio
asyncio.create_task(get_data(textbox))
@when("keydown", "#search_box")
def click_handler(event):
if event.key == "Enter":
global page
page=1
from js import document
textbox = document.getElementById("search_box").value
print(textbox)
if len(textbox)>0:
import asyncio
asyncio.create_task(get_data(textbox))
import js
search = js.window.location.search
params = js.URLSearchParams.new(search)
print('q_value')
if params.has("q"):
q_value = params.get("q")
else:
q_value = ''
from js import document
document.getElementById("search_box").value=q_value
if len(q_value)>0:
import asyncio
asyncio.create_task(get_data(q_value))