-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Add web program to fetch top 10 real time billionaires using the forbes API. #7538
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
Changes from 2 commits
e43c528
e9baf8f
c85adac
b89040d
a4b2df8
ac5e839
cc8a460
e05ef42
05c8a6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ scikit-fuzzy | |
sklearn | ||
statsmodels | ||
sympy | ||
tabulate | ||
tensorflow | ||
texttable | ||
tweepy | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,41 @@ | ||||||||||||||||
from datetime import date, datetime | ||||||||||||||||
|
||||||||||||||||
import requests | ||||||||||||||||
import tabulate | ||||||||||||||||
|
||||||||||||||||
API_URL = ( | ||||||||||||||||
"https://www.forbes.com/forbesapi/person/rtb/0/-estWorthPrev/true.json" | ||||||||||||||||
"?fields=personName,gender,source,countryOfCitizenship," | ||||||||||||||||
"birthDate,finalWorth&limit=10" | ||||||||||||||||
) | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
def real_time_billionaires() -> str: | ||||||||||||||||
"""Get top 10 realtime billionaires using forbes API | ||||||||||||||||
Returns: | ||||||||||||||||
Top 10 realtime billionaires date in tabulated string. | ||||||||||||||||
""" | ||||||||||||||||
response_json = requests.get(API_URL).json() | ||||||||||||||||
today = date.today() | ||||||||||||||||
final_response = [] | ||||||||||||||||
for person in response_json["personList"]["personsLists"]: | ||||||||||||||||
birthdate = datetime.fromtimestamp(person["birthDate"] / 1000).date() | ||||||||||||||||
final_response.append( | ||||||||||||||||
{ | ||||||||||||||||
"Name": person["personName"], | ||||||||||||||||
"Source": person["source"], | ||||||||||||||||
"Country": person["countryOfCitizenship"], | ||||||||||||||||
"Gender": person["gender"], | ||||||||||||||||
"Worth": f"{person['finalWorth'] / 1000:.1f} Billion", | ||||||||||||||||
"Age": today.year | ||||||||||||||||
- birthdate.year | ||||||||||||||||
- ((today.month, today.day) < (birthdate.month, birthdate.day)), | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that psf/black will reformat this back to the original solution (terms on separate lines). For There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you. This has been modified here: c85adac |
||||||||||||||||
} | ||||||||||||||||
) | ||||||||||||||||
header = tuple(final_response[0].keys()) | ||||||||||||||||
rows = [x.values() for x in final_response] | ||||||||||||||||
return tabulate.tabulate(rows, header) | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
if __name__ == "__main__": | ||||||||||||||||
print(real_time_billionaires()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a comment syntax that some editors (PyCharm, I think) prefer so we should leave it as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this was automatically done by PyCharm. However, I've modified it a bit. c85adac