Skip to content

Commit

Permalink
rewrite in python
Browse files Browse the repository at this point in the history
  • Loading branch information
madnight committed Dec 15, 2023
1 parent b05d58d commit f1625c8
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 0 deletions.
2 changes: 2 additions & 0 deletions py/config.ini
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
37 changes: 37 additions & 0 deletions py/main.py
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"))
178 changes: 178 additions & 0 deletions py/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions py/pyproject.toml
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"]

0 comments on commit f1625c8

Please sign in to comment.