Created
February 10, 2024 14:37
-
-
Save aburjg/67d45bd3a7eb4aace2c76f86c5912001 to your computer and use it in GitHub Desktop.
stocks app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from quickchart import QuickChart | |
qc = QuickChart() | |
qc.width = 800 | |
qc.height = 400 | |
qc.version = '2' | |
def chart(x,y): | |
i = [str(i) for i in range(len(x))] | |
qc.config = f"""{{ | |
type: 'line', | |
data: {{ | |
labels: {i}, | |
datasets: [ | |
{{ | |
backgroundColor: 'rgba(255, 99, 132, 0.5)', | |
borderColor: 'rgb(255, 99, 132)', | |
data: {x}, | |
label: '{y}', | |
fill: false, | |
}}, | |
], | |
}}, | |
options: {{ | |
scales: {{ | |
xAxes: [ | |
{{ | |
ticks: {{ | |
autoSkip: false, | |
maxRotation: 0, | |
}}, | |
}}, | |
], | |
}}, | |
title: {{ | |
text: 'fill: false', | |
display: true, | |
}}, | |
}}, | |
}}""" | |
return qc.get_url() | |
##=== | |
import yfinance as yf | |
from sarya import Sarya, UI | |
sarya = Sarya(key="sk-...") | |
from datetime import datetime, timedelta | |
def stock_list(symbol): | |
end_date = datetime.today() | |
start_date = end_date - timedelta(days=30) | |
data = yf.download(symbol, start=start_date, end=end_date) | |
close_prices = data['Close'].tolist() | |
return close_prices | |
def stock(symbol): | |
data = yf.download(symbol, period='1d') | |
return data.Open[0] | |
def main(messages): | |
try: | |
input = messages[0]["content"] | |
price = stock(input) | |
return [UI.Image(chart(stock_list(input),input)), | |
UI.Text(f"price of {input}: {price:0.2f}")] | |
except: | |
return UI.Text("👎") | |
sarya.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment