mirror of
https://github.com/ihabunek/toot.git
synced 2024-11-03 04:17:21 -05:00
Remove duplicate search api fn
This commit is contained in:
parent
ebc17e0764
commit
7b194880a0
@ -350,6 +350,7 @@ def test_search(mock_get, capsys):
|
||||
|
||||
mock_get.assert_called_once_with(app, user, '/api/v2/search', {
|
||||
'q': 'freddy',
|
||||
'type': None,
|
||||
'resolve': False,
|
||||
})
|
||||
|
||||
|
21
toot/api.py
21
toot/api.py
@ -278,21 +278,18 @@ def upload_media(app, user, file, description=None):
|
||||
).json()
|
||||
|
||||
|
||||
def search(app, user, query, resolve):
|
||||
return http.get(app, user, '/api/v2/search', {
|
||||
'q': query,
|
||||
'resolve': resolve,
|
||||
def search(app, user, query, resolve=False, type=None):
|
||||
"""
|
||||
Perform a search.
|
||||
https://docs.joinmastodon.org/methods/search/#v2
|
||||
"""
|
||||
return http.get(app, user, "/api/v2/search", {
|
||||
"q": query,
|
||||
"resolve": resolve,
|
||||
"type": type
|
||||
}).json()
|
||||
|
||||
|
||||
def search_accounts(app, user, query):
|
||||
return http.get(app, user, '/api/v2/search', {
|
||||
'q': query,
|
||||
'type': 'accounts',
|
||||
'resolve': True,
|
||||
}).json()['accounts']
|
||||
|
||||
|
||||
def follow(app, user, account):
|
||||
return _account_action(app, user, account, 'follow')
|
||||
|
||||
|
@ -255,14 +255,11 @@ def _find_account(app, user, account_name):
|
||||
if not account_name:
|
||||
raise ConsoleError("Empty account name given")
|
||||
|
||||
accounts = api.search_accounts(app, user, account_name)
|
||||
normalized_name = account_name.lstrip("@").lower()
|
||||
|
||||
if account_name[0] == "@":
|
||||
account_name = account_name[1:]
|
||||
|
||||
for account in accounts:
|
||||
# Normalise string matching because usernames are case insensitive
|
||||
if account['acct'].lower() == account_name.lower():
|
||||
response = api.search(app, user, account_name, type="accounts", resolve=True)
|
||||
for account in response["accounts"]:
|
||||
if account["acct"].lower() == normalized_name:
|
||||
return account
|
||||
|
||||
raise ConsoleError("Account not found")
|
||||
|
Loading…
Reference in New Issue
Block a user