mariostoev/finviz

finviz.get_stock() - two fields have the same name

Closed this issue · 1 comments

bibsn commented

Dear,
In the table of the stock quote, there are two fields that have the same name but different information.
the name is "EPS next year", the first one is a number and the second one is a percentage.
Capture

Can you modify the code that in row 5 and column 5 change the key of dictionary from "EPS next year" into "EPS next year %"
Thanks

bibsn commented

I solve the issue with this modification in mani_func.py:

def get_stock(ticker):
"""
Returns a dictionary containing stock data.

:param ticker: stock symbol
:type ticker: str
:return dict
"""

get_page(ticker)
page_parsed = STOCK_PAGE[ticker]

title = page_parsed.cssselect('table[class="fullview-title"]')[0]
keys = ["Company", "Sector", "Industry", "Country"]
fields = [f.text_content() for f in title.cssselect('a[class="tab-link"]')]
data = dict(zip(keys, fields))

all_rows = [
    row.xpath("td//text()")
    for row in page_parsed.cssselect('tr[class="table-dark-row"]')
]

for i, row in enumerate(all_rows):
    for column in range(0, 11, 2):
        if i == 4 and column == 4:
            data["EPS next year%"] = row[column + 1]
        else:
            data[row[column]] = row[column + 1]

return data