Skip to content

fix: modify the depracated code and add new tests #11465

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

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions web_programming/get_top_billionaires.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
This works for some of us but fails for others.
"""

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

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

LIMIT = 10
TODAY = datetime.now(tz=UTC)
TODAY = datetime.now(tz=timezone.utc) # noqa: UP017
API_URL = (
"https://www.forbes.com/forbesapi/person/rtb/0/position/true.json"
"?fields=personName,gender,source,countryOfCitizenship,birthDate,finalWorth"
Expand Down Expand Up @@ -44,7 +45,7 @@ def years_old(birth_timestamp: int, today: date | None = None) -> int:
True
"""
today = today or TODAY.date()
birth_date = datetime.fromtimestamp(birth_timestamp, tz=UTC).date()
birth_date = datetime.fromtimestamp(birth_timestamp, tz=timezone.utc).date() # noqa: UP017
return (today.year - birth_date.year) - (
(today.month, today.day) < (birth_date.month, birth_date.day)
)
Expand All @@ -65,7 +66,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 +96,5 @@ def display_billionaires(forbes_billionaires: list[dict[str, int | str]]) -> Non


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