Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyst Rating: Bug #145

Open
bruce1095 opened this issue Dec 24, 2022 · 3 comments
Open

Analyst Rating: Bug #145

bruce1095 opened this issue Dec 24, 2022 · 3 comments

Comments

@bruce1095
Copy link

this still returns an empty string

finviz.get_analyst_price_targets("AAPL")

@bruce1095
Copy link
Author

***returns an empty list:
finviz.get_analyst_price_targets("AAPL")
Out[77]:

@glitchawy
Copy link

same error here
I found a closed issue for this but I didn't understand it #142

@glitchawy
Copy link

glitchawy commented Aug 20, 2023

Just found the cause of the problem :
Firstly the try and except statement always made the function pass until it return an empty list .. so I firstly removed it and then i found that the function was trying to convert the first row of the table that has strings using strptime() function ..
now you can make a counter to pass the first row and start from the second like this :
`

analyst_price_targets = []
get_page(ticker)
page_parsed = STOCK_PAGE[ticker]
table = page_parsed.cssselect(
    'table[class="js-table-ratings fullview-ratings-outer"]'
)[0]
counter = 0
for row in table:
    counter+=1
    if counter == 1 :
        pass
    else :
        rating = row.xpath("td//text()")
        rating = [val.replace("→", "->").replace("$", "") for val in rating if val != "\n"]
        rating[0] = datetime.strptime(rating[0], "%b-%d-%y").strftime("%Y-%m-%d")

        data = {
            "date": rating[0],
            "category": rating[1],
            "analyst": rating[2],
            "rating": rating[3],
        }
        if len(rating) == 5:
            if "->" in rating[4]:
                rating.extend(rating[4].replace(" ", "").split("->"))
                del rating[4]
                data["target_from"] = float(rating[4])
                data["target_to"] = float(rating[5])
            else:
                data["target"] = float(rating[4])

        analyst_price_targets.append(data)
        
return analyst_price_targets[:last_ratings]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants