Commit
β’
cad28e4
1
Parent(s):
c5a4ed0
try and then clean and fail
Browse files
app.py
CHANGED
@@ -14,33 +14,33 @@ def get_did_from_handle(handle: str) -> str:
|
|
14 |
Get the DID for a given Bluesky handle.
|
15 |
|
16 |
Args:
|
17 |
-
handle (str): Bluesky handle (
|
18 |
|
19 |
Returns:
|
20 |
str: Success or error message
|
21 |
"""
|
22 |
-
# Clean the handle
|
23 |
-
handle = clean_handle(handle)
|
24 |
-
|
25 |
if not handle:
|
26 |
return "Error: Please enter a handle"
|
27 |
|
28 |
-
if not handle.endswith('.bsky.social'):
|
29 |
-
return "Error: Handle must end with .bsky.social"
|
30 |
-
|
31 |
# Initialize client
|
32 |
client = Client()
|
33 |
|
|
|
34 |
try:
|
35 |
-
# Attempt to resolve handle
|
36 |
response = client.resolve_handle(handle)
|
37 |
return f"DID: {response.did}"
|
38 |
-
except BadRequestError
|
39 |
-
#
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
except Exception as e:
|
45 |
return f"Error: {str(e)}"
|
46 |
|
@@ -51,18 +51,20 @@ demo = gr.Interface(
|
|
51 |
gr.Textbox(
|
52 |
label="Enter Bluesky Handle",
|
53 |
placeholder="username.bsky.social",
|
54 |
-
info="Enter a Bluesky handle to get its DID (without
|
55 |
)
|
56 |
],
|
57 |
outputs=gr.Textbox(label="Result"),
|
58 |
title="Bluesky DID Lookup",
|
59 |
-
description="Look up the DID (Decentralized Identifier) for any Bluesky handle
|
60 |
examples=[
|
61 |
["atproto.bsky.social"],
|
62 |
["bsky.app"],
|
63 |
["danielvanstrien.bsky.social"],
|
|
|
64 |
],
|
65 |
theme=gr.themes.Default(),
|
|
|
66 |
)
|
67 |
|
68 |
if __name__ == "__main__":
|
|
|
14 |
Get the DID for a given Bluesky handle.
|
15 |
|
16 |
Args:
|
17 |
+
handle (str): Bluesky handle (any valid format)
|
18 |
|
19 |
Returns:
|
20 |
str: Success or error message
|
21 |
"""
|
|
|
|
|
|
|
22 |
if not handle:
|
23 |
return "Error: Please enter a handle"
|
24 |
|
|
|
|
|
|
|
25 |
# Initialize client
|
26 |
client = Client()
|
27 |
|
28 |
+
# First try: raw input
|
29 |
try:
|
|
|
30 |
response = client.resolve_handle(handle)
|
31 |
return f"DID: {response.did}"
|
32 |
+
except BadRequestError:
|
33 |
+
# Second try: cleaned input
|
34 |
+
try:
|
35 |
+
cleaned_handle = clean_handle(handle)
|
36 |
+
if cleaned_handle != handle: # Only try if cleaning actually changed something
|
37 |
+
response = client.resolve_handle(cleaned_handle)
|
38 |
+
return f"DID: {response.did}"
|
39 |
+
except BadRequestError as e:
|
40 |
+
return (f"Error: Could not resolve handle. Please check the format.\n"
|
41 |
+
f"Tried both '{handle}' and '{cleaned_handle}'")
|
42 |
+
except Exception as e:
|
43 |
+
return f"Error: {str(e)}"
|
44 |
except Exception as e:
|
45 |
return f"Error: {str(e)}"
|
46 |
|
|
|
51 |
gr.Textbox(
|
52 |
label="Enter Bluesky Handle",
|
53 |
placeholder="username.bsky.social",
|
54 |
+
info="Enter a Bluesky handle to get its DID (with or without @ symbol)"
|
55 |
)
|
56 |
],
|
57 |
outputs=gr.Textbox(label="Result"),
|
58 |
title="Bluesky DID Lookup",
|
59 |
+
description="Look up the DID (Decentralized Identifier) for any Bluesky handle.<br><br>Built by <a href='https://bsky.app/profile/danielvanstrien.bsky.social'>@danielvanstrien.bsky.social</a><br>Part of <a href='https://huggingface.co/bluesky-community'>Bluesky Community</a>",
|
60 |
examples=[
|
61 |
["atproto.bsky.social"],
|
62 |
["bsky.app"],
|
63 |
["danielvanstrien.bsky.social"],
|
64 |
+
["@jay.bsky.team"],
|
65 |
],
|
66 |
theme=gr.themes.Default(),
|
67 |
+
allow_flagging="never"
|
68 |
)
|
69 |
|
70 |
if __name__ == "__main__":
|