Skip to content

Commit 2b89aca

Browse files
committed
README/example: Condense the readme example, more output on error
1 parent 55efb83 commit 2b89aca

2 files changed

Lines changed: 22 additions & 34 deletions

File tree

README.md

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ async def async_main():
101101
tokens = f.read()
102102
# Assign gathered tokens
103103
auth_mgr.oauth = OAuth2TokenResponse.parse_raw(tokens)
104-
except FileNotFoundError:
105-
print(f"File {tokens_file} isn`t found or it doesn`t contain tokens!")
106-
exit(-1)
104+
except FileNotFoundError as e:
105+
print(
106+
f"File {tokens_file} isn`t found or it doesn`t contain tokens! err={e}"
107+
)
108+
sys.exit(-1)
107109

108110
"""
109111
Refresh tokens, just in case
@@ -112,8 +114,8 @@ async def async_main():
112114
"""
113115
try:
114116
await auth_mgr.refresh_tokens()
115-
except HTTPStatusError:
116-
print("Could not refresh tokens")
117+
except HTTPStatusError as e:
118+
print(f"Could not refresh tokens, err={e}")
117119
sys.exit(-1)
118120

119121
# Save the refreshed/updated tokens
@@ -131,29 +133,21 @@ async def async_main():
131133
"""
132134
# Get friendslist
133135
friendslist = await xbl_client.people.get_friends_own()
134-
print("Your friends:")
135-
print(friendslist)
136-
print()
136+
print(f"Your friends: {friendslist}\n")
137137

138138
# Get presence status (by list of XUID)
139139
presence = await xbl_client.presence.get_presence_batch(
140140
["2533274794093122", "2533274807551369"]
141141
)
142-
print("Statuses of some random players by XUID:")
143-
print(presence)
144-
print()
142+
print(f"Statuses of some random players by XUID: {presence}\n")
145143

146144
# Get messages
147145
messages = await xbl_client.message.get_inbox()
148-
print("Your messages:")
149-
print(messages)
150-
print()
146+
print(f"Your messages: {messages}\n")
151147

152148
# Get profile by GT
153149
profile = await xbl_client.profile.get_profile_by_gamertag("SomeGamertag")
154-
print("Profile under SomeGamertag gamer tag:")
155-
print(profile)
156-
print()
150+
print(f"Profile under SomeGamertag gamer tag: {profile}\n")
157151

158152

159153
asyncio.run(async_main())

readme_example.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ async def async_main():
4040
tokens = f.read()
4141
# Assign gathered tokens
4242
auth_mgr.oauth = OAuth2TokenResponse.parse_raw(tokens)
43-
except FileNotFoundError:
44-
print(f"File {tokens_file} isn`t found or it doesn`t contain tokens!")
45-
exit(-1)
43+
except FileNotFoundError as e:
44+
print(
45+
f"File {tokens_file} isn`t found or it doesn`t contain tokens! err={e}"
46+
)
47+
sys.exit(-1)
4648

4749
"""
4850
Refresh tokens, just in case
@@ -51,8 +53,8 @@ async def async_main():
5153
"""
5254
try:
5355
await auth_mgr.refresh_tokens()
54-
except HTTPStatusError:
55-
print("Could not refresh tokens")
56+
except HTTPStatusError as e:
57+
print(f"Could not refresh tokens, err={e}")
5658
sys.exit(-1)
5759

5860
# Save the refreshed/updated tokens
@@ -70,29 +72,21 @@ async def async_main():
7072
"""
7173
# Get friendslist
7274
friendslist = await xbl_client.people.get_friends_own()
73-
print("Your friends:")
74-
print(friendslist)
75-
print()
75+
print(f"Your friends: {friendslist}\n")
7676

7777
# Get presence status (by list of XUID)
7878
presence = await xbl_client.presence.get_presence_batch(
7979
["2533274794093122", "2533274807551369"]
8080
)
81-
print("Statuses of some random players by XUID:")
82-
print(presence)
83-
print()
81+
print(f"Statuses of some random players by XUID: {presence}\n")
8482

8583
# Get messages
8684
messages = await xbl_client.message.get_inbox()
87-
print("Your messages:")
88-
print(messages)
89-
print()
85+
print(f"Your messages: {messages}\n")
9086

9187
# Get profile by GT
9288
profile = await xbl_client.profile.get_profile_by_gamertag("SomeGamertag")
93-
print("Profile under SomeGamertag gamer tag:")
94-
print(profile)
95-
print()
89+
print(f"Profile under SomeGamertag gamer tag: {profile}\n")
9690

9791

9892
asyncio.run(async_main())

0 commit comments

Comments
 (0)