-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[Symbols] | ||
stocks = AAPL,MSFT,GOOGL,INTC,AMD,PEP,MU,TSLA,NFLX,DIS,AMZN,SPY,QQQ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import requests | ||
import configparser | ||
from tabulate import tabulate | ||
|
||
def read_config_file(filename): | ||
config = configparser.ConfigParser() | ||
config.read(filename) | ||
|
||
symbols = config.get('Symbols', 'stocks') | ||
return symbols.split(',') | ||
|
||
stocks = read_config_file('config.ini') | ||
|
||
url = "http://127.0.0.1:5000/{}".format(','.join(stocks)) | ||
response = requests.get(url) | ||
|
||
# Parse the API response | ||
data = response.json() | ||
|
||
# Extract the required fields and store them in a list of dictionaries | ||
extracted_data = [] | ||
for stock in data: | ||
for symbol, details in stock.items(): | ||
extracted_data.append({ | ||
"Symbol": symbol, | ||
"Price": round(float(details["Price"]), 2), | ||
"Change": details["Change"], | ||
"Average Volume": details["Avg Volume"], | ||
"P/E": details["P/E"], | ||
"Market Cap": details["Market Cap"], | ||
"52W Low": details["52W Low"], | ||
"52W High": details["52W High"], | ||
"YTD Change": details["Perf YTD"], | ||
}) | ||
|
||
# Print the data in a table format using tabulate | ||
print(tabulate(extracted_data, headers="keys", tablefmt="simple_outline")) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[tool.poetry] | ||
name = "wallstreet" | ||
version = "0.1.0" | ||
description = "" | ||
authors = ["Fabian Beuke <mail@beuke.org>"] | ||
readme = "README.md" | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.11" | ||
requests = "^2.31.0" | ||
tabulate = "^0.9.0" | ||
|
||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" | ||
|
||
[include] | ||
include = ["config.ini"] |