Skip to content

Commit

Permalink
recent searches retrieve method
Browse files Browse the repository at this point in the history
  • Loading branch information
KolyaDobrydnev committed Aug 15, 2023
1 parent 8c09d3f commit ecdbc29
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion instagrapi/mixins/fbsearch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing import List, Dict, Tuple, Union

from instagrapi.extractors import (
extract_hashtag_v1,
Expand Down Expand Up @@ -73,3 +73,34 @@ def fbsearch_suggested_profiles(self, user_id: str) -> List[UserShort]:
}
result = self.private_request("fbsearch/accounts_recs/", params=params)
return result["users"]

def fbsearch_recent(self) -> List[Tuple[int, Union[UserShort, Hashtag, Dict]]]:
'''
Retrieves recently searched results
Returns
-------
List[Tuple[int, Union[UserShort, Hashtag, Dict]]]
Returns list of Tuples where first value is timestamp of searh, second is retrived result
'''
result = self.private_request("fbsearch/recent_searches/")
assert result.get("status", "") == "ok", "Failed to retrieve recent searches"

data = []
for item in result.get("recent", []):
if "user" in item.keys():
data.append((
item.get("client_time", None),
extract_user_short(item['user'])))
if "hashtag" in item.keys():
hashtag = item.get("hashtag")
hashtag["media_count"] = hashtag.pop("formatted_media_count")
data.append((
item.get("client_time", None),
Hashtag(**hashtag)))
if "keyword" in item.keys():
data.append((
item.get("client_time", None),
item["keyword"]
))
return data

0 comments on commit ecdbc29

Please sign in to comment.