2023-05-03 08:54:36 +00:00
|
|
|
from flask import Flask, jsonify, redirect, url_for, send_from_directory
|
2023-05-03 08:07:34 +00:00
|
|
|
from flask_cors import CORS
|
2023-05-03 08:54:36 +00:00
|
|
|
from backend.utils.build_frontend import build_frontend
|
2023-05-08 10:16:06 +00:00
|
|
|
from backend.api.companies import get_companies
|
2023-05-03 08:54:36 +00:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
2023-05-03 08:07:34 +00:00
|
|
|
|
2023-05-08 10:16:06 +00:00
|
|
|
ROOT_DIR: str = os.path.dirname(__file__)
|
|
|
|
|
2023-05-03 08:07:34 +00:00
|
|
|
# instantiate the app
|
|
|
|
app = Flask(__name__, static_url_path='/static', static_folder='stockingly-frontend/dist')
|
|
|
|
app.config.from_object(__name__)
|
|
|
|
|
|
|
|
# enable CORS
|
|
|
|
CORS(app, resources={r'/*': {'origins': '*'}})
|
|
|
|
|
2023-05-03 08:54:36 +00:00
|
|
|
|
|
|
|
@app.route('/', methods=['GET'])
|
|
|
|
def index():
|
|
|
|
return redirect(url_for('static', filename='index.html'))
|
|
|
|
|
2023-05-03 08:07:34 +00:00
|
|
|
|
2023-05-08 10:16:06 +00:00
|
|
|
@app.route('/companies', methods=['GET'])
|
|
|
|
def companies() -> object:
|
|
|
|
return jsonify(get_companies(ROOT_DIR))
|
|
|
|
|
|
|
|
|
2023-05-15 09:50:07 +00:00
|
|
|
@app.route('/companies/logos/<ticker>')
|
|
|
|
def get_company_logo(ticker: str):
|
|
|
|
logo_dir: str = os.path.join(ROOT_DIR, 'scraper', 'logos', 'logos')
|
|
|
|
logo_name: str = str(ticker).upper() + '.png'
|
|
|
|
|
|
|
|
if os.path.exists(os.path.join(logo_dir, logo_name)):
|
|
|
|
return send_from_directory(logo_dir, logo_name)
|
|
|
|
|
|
|
|
return send_from_directory(ROOT_DIR, 'company_generic.svg')
|
|
|
|
|
|
|
|
|
2023-05-03 08:07:34 +00:00
|
|
|
if __name__ == '__main__':
|
2023-05-03 08:54:36 +00:00
|
|
|
build_frontend()
|
|
|
|
app.run()
|