It's my first time using an API and I'm trying to make my search bar give back results on every letter that is typed ( i succeed to search on words but not on letters yet)
so I made a function that calls the API and returns some data based on the word(symbol) you are going to search
def lookup(symbol):
"""Look up quote for symbol."""
# Contact API
try:
api_key = os.environ.get("API_KEY")
url = f"https://cloud.iexapis.com/stable/stock/{urllib.parse.quote_plus(symbol)}/quote?token={api_key}"
response = requests.get(url)
response.raise_for_status()
except requests.RequestException:
return None
# Parse response
try:
quote = response.json()
return {
"name": quote["companyName"],
"price": float(quote["latestPrice"]),
"symbol": quote["symbol"]
}
except (KeyError, TypeError, ValueError):
return None
this is my simple form
<form action="/search" method="GET">
<input
type="search"
autofocus
name="symbol"
id="symbol"
placeholder="Write a stock quote"
/>
Can anyone give me an idea on how to do it, typing a letter and not a word? With javascript or directly on python