mirror of https://github.com/Textualize/rich.git
tidy example
This commit is contained in:
parent
c155e81bf5
commit
a81abc935b
|
@ -1,20 +1,19 @@
|
|||
import json
|
||||
from urllib.request import urlopen
|
||||
|
||||
|
||||
from rich import print
|
||||
from rich.columns import Columns
|
||||
from rich.panel import Panel
|
||||
|
||||
users = json.loads(urlopen("https://randomuser.me/api/?results=30").read())["results"]
|
||||
print(users)
|
||||
|
||||
|
||||
def get_content(user):
|
||||
"""Extract text from user dict."""
|
||||
country = user["location"]["country"]
|
||||
name = f"{user['name']['first']} {user['name']['last']}"
|
||||
return f"[b]{name}[/b]\n[yellow]{country}"
|
||||
|
||||
|
||||
users = json.loads(urlopen("https://randomuser.me/api/?results=30").read())["results"]
|
||||
print(users)
|
||||
user_renderables = [Panel(get_content(user), expand=False) for user in users]
|
||||
print(Columns(user_renderables))
|
||||
|
|
Loading…
Reference in New Issue