henrydatei / wikifolio-api

A Python API-Wrapper for the unofficial wikifolio API
GNU General Public License v3.0
17 stars 4 forks source link

ranking_place returns ranking value/points #18

Closed TryThis closed 8 months ago

TryThis commented 8 months ago

Hi,

the function ranking_place returns the value / points of the ranking but not the ranking place.

if you would add /change the following properties

   @property
    def ranking_place(self) -> typing.Optional[int]:
        return self._get_wikifolio_key_figure("rankingPlace")

    @property
    def ranking_points(self) -> typing.Optional[float]:
        return self._get_wikifolio_key_figure(1, 0)

and change the function towards

   def _get_wikifolio_key_figure(self, metric, submetric = 0, section = "kpis") -> typing.Optional[float]:
        try:
            key_figures = self.rawData["props"]["pageProps"]["data"]["keyFigures"]
            if metric == "totalInvestments" or metric == "tradingVolume" or metric == "liquidationFigure":
                return key_figures[metric]["ranking"]["value"]
            elif metric == "rankingPlace":
                return key_figures["kpis"][1]["rankings"][0]["ranking"]["place"]
            else:
                return key_figures[section][metric]["rankings"][submetric]["ranking"]["value"]
        except Exception as e:
            print("Error at _get_wikifolio_key_figure -> Open a issue on GitHub: " + str(e))
            return None

you could deliver both points and the right ranking place.

henrydatei commented 8 months ago

implemented, thanks for your code :)

TryThis commented 8 months ago

You're welcome. Your library will save me a lot of time 😀