I built a coro function within a pyscript tag that outputs a location of the space station using folium to the web
from pyodide.http import pyfetch
import asyncio
import folium
async def get_ISS_locdata():
response = await pyfetch("http://api.open-notify.org/iss-now.json", method="GET")
data = await response.json()
iss_pos = data.get("iss_position")
latitude = iss_pos["latitude"]
longitude = iss_pos["longitude"]
iss_coords = [float(latitude), float(longitude)]
iss_map = folium.Map(location = iss_coords, zoom_start = 3)
folium.Marker(iss_coords, icon=icon, popup="<h4>International Space Station</h4>").add_to(iss_map)
iss_map
Element("map").write(iss_map)
output = f"ISS Current Location - Latitude: {latitude}, Longitude: {longitude}"
Element("output").write(output)
since pyscript is a running event loop,
<pyscript._event_loop.PyscriptWebLoop object at 0x10b8470>
I call the coro like this:
asyncio.ensure_future(get_ISS_locdata())
It worked.
Then I tried to create a coro interval function to update latitude and longitude of the space station:
async def interval(seconds, func):
while True:
await func()
await asyncio.sleep(seconds)
asyncio.ensure_future(interval(3, get_ISS_locdata()))
and gave me an error:
Task exception was never retrieved
future: <Task finished name='Task-17' coro=<interval() done, defined at <exec>:28> exception=TypeError("'coroutine' object is not callable")>
sys:1: RuntimeWarning: coroutine 'get_ISS_locdata' was never awaited
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
I also did to ensure future and create task but same error occured.
Is there other way to call the get_ISS_locdata coro?