diff --git a/company_generic.svg b/company_generic.svg new file mode 100644 index 0000000..c935139 --- /dev/null +++ b/company_generic.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/stockingly-frontend/src/api/index.ts b/stockingly-frontend/src/api/index.ts index 2dbc27e..61298e2 100644 --- a/stockingly-frontend/src/api/index.ts +++ b/stockingly-frontend/src/api/index.ts @@ -13,7 +13,11 @@ export interface Company { tags: string[]; ticker: string; website: string; + logoSrc: string } export const getCompanies = (): Promise => - fetch(BACKEND_URL + '/companies').then(r => r.json()) \ No newline at end of file + fetch(BACKEND_URL + '/companies').then(r => r.json()).then(list => list.map((e: Company) => ({ + ...e, + logoSrc: `${BACKEND_URL}/companies/logos/${e.ticker}` + }))); \ No newline at end of file diff --git a/stockingly-frontend/src/views/Home.vue b/stockingly-frontend/src/views/Home.vue index 6f9bff1..789b8d3 100644 --- a/stockingly-frontend/src/views/Home.vue +++ b/stockingly-frontend/src/views/Home.vue @@ -9,10 +9,16 @@ - - {{ company['short name'] }} - {{ company['company name'] }} - + + + + + + + {{ company['short name'] }} + {{ company['company name'] }} + + @@ -21,9 +27,9 @@ {{ m.title }} - {{ m.value }}{{ m.symbol ?? '' }} + {{ m.value(company) }}{{ m.symbol ?? '' }} - + @@ -59,7 +65,7 @@ interface Metric { color: string, minValue: number, maxValue: number, - value: number // in [0, 100], + value: (c: Company) => number // in [0, 100], symbol?: string } @@ -69,21 +75,21 @@ const metricsData = reactive([ color: 'green', minValue: 0, maxValue: 100, - value: 20 + value: _ => 20 }, { - title: 'Metric 2', + title: 'Length of ticker', color: 'orange', minValue: 0, - maxValue: 100, - value: 60, - symbol: '%' + maxValue: 5, + value: c => c.ticker.length, + symbol: ' chars' }, ]); -const metrics = computed<(Metric & { percentage: number })[]>(() => metricsData.map(e => ({ +const metrics = computed<(Metric & { percentage: (c: Company) => number })[]>(() => metricsData.map(e => ({ ...e, - percentage: (e.value - e.minValue) * 100 / (e.maxValue - e.minValue) + percentage: (c: Company) => (e.value(c) - e.minValue) * 100 / (e.maxValue - e.minValue) }))); diff --git a/stockingly.py b/stockingly.py index 3ed9e56..069840a 100644 --- a/stockingly.py +++ b/stockingly.py @@ -26,6 +26,17 @@ def companies() -> object: return jsonify(get_companies(ROOT_DIR)) +@app.route('/companies/logos/') +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') + + if __name__ == '__main__': build_frontend() app.run()
@@ -21,9 +27,9 @@