mirror of
https://github.com/ihabunek/toot.git
synced 2024-11-03 04:17:21 -05:00
Support bookmarking a status by URL
Addresses issue #386 but not in every case.
This commit is contained in:
parent
4f62f417f8
commit
0da15d9e68
10
toot/api.py
10
toot/api.py
@ -458,6 +458,16 @@ def search(app, user, query, resolve=False, type=None):
|
||||
}).json()
|
||||
|
||||
|
||||
def search_url(app, user, query):
|
||||
"""
|
||||
Perform a search for a URL as is, without encoding.
|
||||
https://docs.joinmastodon.org/methods/search/#v2
|
||||
"""
|
||||
# The Request object performs form encoding if a dict is passed
|
||||
return http.get(app, user, "/api/v2/search?q={}&resolve=true".format(query)
|
||||
).json()
|
||||
|
||||
|
||||
def follow(app, user, account):
|
||||
return _account_action(app, user, account, 'follow')
|
||||
|
||||
|
@ -242,8 +242,18 @@ def unpin(app, user, args):
|
||||
|
||||
|
||||
def bookmark(app, user, args):
|
||||
api.bookmark(app, user, args.status_id)
|
||||
print_out("<green>✓ Status bookmarked</green>")
|
||||
if "://" in args.status_id:
|
||||
print_out("Not a status ID but an URL was provided. Attempting to fetch a status ID.")
|
||||
result = api.search_url(app, user, args.status_id)
|
||||
if result.get("statuses"):
|
||||
status_id = result.get("statuses")[0].get("id")
|
||||
else:
|
||||
print_out(f"<red>Status not found for {args.status_id}</red>")
|
||||
return
|
||||
else:
|
||||
status_id = args.status_id
|
||||
api.bookmark(app, user, status_id)
|
||||
print_out(f"<green>✓ Status {status_id} bookmarked</green>")
|
||||
|
||||
|
||||
def unbookmark(app, user, args):
|
||||
@ -366,7 +376,11 @@ def upload(app, user, args):
|
||||
|
||||
|
||||
def search(app, user, args):
|
||||
response = api.search(app, user, args.query, args.resolve)
|
||||
print_out(args.query)
|
||||
if "://" in args.query:
|
||||
response = api.search_url(app, user, args.query)
|
||||
else:
|
||||
response = api.search(app, user, args.query, args.resolve)
|
||||
print_search_results(response)
|
||||
|
||||
|
||||
|
@ -260,8 +260,9 @@ def print_list_accounts(accounts):
|
||||
|
||||
|
||||
def print_search_results(results):
|
||||
accounts = results['accounts']
|
||||
hashtags = results['hashtags']
|
||||
accounts = results.get("accounts")
|
||||
hashtags = results.get("hashtags")
|
||||
statuses = results.get("results")
|
||||
|
||||
if accounts:
|
||||
print_out("\nAccounts:")
|
||||
@ -271,7 +272,11 @@ def print_search_results(results):
|
||||
print_out("\nHashtags:")
|
||||
print_out(", ".join([f"<green>#{t['name']}</green>" for t in hashtags]))
|
||||
|
||||
if not accounts and not hashtags:
|
||||
if statuses:
|
||||
print_out("\nStatuses:")
|
||||
print_out(", ".join([f"<green>#{t['id']}</green>" for t in statuses]))
|
||||
|
||||
if not accounts and not hashtags and not statuses:
|
||||
print_out("<yellow>Nothing found</yellow>")
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user