-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
43 lines (33 loc) · 1.2 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import io
import flask
from zipfile import ZipFile
from flask import Flask, make_response
from flask_cors import CORS
from utils.stock_scraper import Fundamentus
from flask import Response
import json
app = Flask(__name__)
CORS(app)
fundamentus = Fundamentus()
@app.route('/', methods=['GET'])
def test_api() -> dict:
return {"status": "Up!"}
@app.route('/events/<ticker>', methods=['GET'])
def get_events(ticker:str) -> dict:
return fundamentus.get_events(ticker).to_dict()
@app.route('/info/<ticker>', methods=['GET'])
def get_info(ticker:str) -> dict:
return fundamentus.get_stock_info(ticker).to_dict()
@app.route('/dividends/<ticker>', methods=['GET'])
def get_dividends(ticker:str) -> dict:
return fundamentus.get_dividends(ticker).to_dict()
@app.route('/fundamentals/<ticker>', methods=['GET'])
def get_fundamentals(ticker:str) -> dict:
bytes_zip = fundamentus.get_fundamentals(ticker)
zip_file = io.BytesIO(bytes_zip)
return flask.send_file(zip_file, download_name=f'{ticker}.zip')
@app.route('/tickers', methods=['GET'])
def get_tickers() -> dict:
return fundamentus.get_tickers().to_dict()
if __name__ == '__main__':
app.run()