Skip to content

Fix/fixes get top billionaries code #11466

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

Merged
8 changes: 6 additions & 2 deletions web_programming/get_top_billionaires.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
This works for some of us but fails for others.
"""

from datetime import UTC, date, datetime
import doctest
from datetime import date, datetime, timedelta, timezone

import requests
from rich import box
from rich import console as rich_console
from rich import table as rich_table

LIMIT = 10
UTC_OFFSET = timedelta(hours=0)
UTC = timezone(UTC_OFFSET)
TODAY = datetime.now(tz=UTC)
API_URL = (
"https://www.forbes.com/forbesapi/person/rtb/0/position/true.json"
Expand Down Expand Up @@ -65,7 +68,7 @@ def get_forbes_real_time_billionaires() -> list[dict[str, int | str]]:
"Country": person["countryOfCitizenship"],
"Gender": person["gender"],
"Worth ($)": f"{person['finalWorth'] / 1000:.1f} Billion",
"Age": years_old(person["birthDate"]),
"Age": str(years_old(person["birthDate"] / 1000)),
}
for person in response_json["personList"]["personsLists"]
]
Expand Down Expand Up @@ -95,4 +98,5 @@ def display_billionaires(forbes_billionaires: list[dict[str, int | str]]) -> Non


if __name__ == "__main__":
doctest.testmod()
display_billionaires(get_forbes_real_time_billionaires())