Skip to content

Commit

Permalink
Black and bump 1.19.3
Browse files Browse the repository at this point in the history
  • Loading branch information
adw0rd committed Aug 10, 2023
1 parent ead1adf commit 5c22e8f
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 61 deletions.
9 changes: 4 additions & 5 deletions instagrapi/extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def extract_media_v1(data):
def extract_media_v1_xma(data):
"""Extract media from Private API"""
media = deepcopy(data)
#media["media_type"] = 10

# media["media_type"] = 10
media["video_url"] = media.get("target_url", "")
media["title"] = media.get("title_text", "")
media["preview_url"] = media.get("preview_url", "")
Expand All @@ -92,7 +92,7 @@ def extract_media_v1_xma(data):
media["header_icon_height"] = media.get("header_icon_height", 0)
media["header_title_text"] = media.get("header_title_text", "")
media["preview_media_fbid"] = media.get("preview_media_fbid", "")

return MediaXma(
**media,
)
Expand Down Expand Up @@ -328,7 +328,7 @@ def extract_direct_message(data):
xma_media_share = data.get("xma_media_share", {})
if xma_media_share:
data["xma_share"] = extract_media_v1_xma(xma_media_share[0])

return DirectMessage(**data)


Expand Down Expand Up @@ -463,4 +463,3 @@ def extract_track(data):
items = re.findall(r"<BaseURL>(.+?)</BaseURL>", data["dash_manifest"])
data["uri"] = html.unescape(items[0]) if items else None
return Track(**data)

77 changes: 51 additions & 26 deletions instagrapi/mixins/direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,10 @@ def direct_send(
"mutation_token": token,
"_uuid": self.uuid,
"btt_dual_send": "false",
"nav_chain": "1qT:feed_timeline:1,1qT:feed_timeline:2,1qT:feed_timeline:3,7Az:direct_inbox:4,7Az:direct_inbox:5,5rG:direct_thread:7",
"nav_chain": (
"1qT:feed_timeline:1,1qT:feed_timeline:2,1qT:feed_timeline:3,"
"7Az:direct_inbox:4,7Az:direct_inbox:5,5rG:direct_thread:7"
),
"is_ae_dual_send": "false",
"offline_threading_id": token,
}
Expand Down Expand Up @@ -444,8 +447,18 @@ def direct_send_file(
method = f"configure_{content_type}"
token = self.generate_mutation_token()
nav_chains = [
"6xQ:direct_media_picker_photos_fragment:1,5rG:direct_thread:2,5ME:direct_quick_camera_fragment:3,5ME:direct_quick_camera_fragment:4,4ju:reel_composer_preview:5,5rG:direct_thread:6,5rG:direct_thread:7,6xQ:direct_media_picker_photos_fragment:8,5rG:direct_thread:9",
"1qT:feed_timeline:1,7Az:direct_inbox:2,7Az:direct_inbox:3,5rG:direct_thread:4,6xQ:direct_media_picker_photos_fragment:5,5rG:direct_thread:6,5rG:direct_thread:7,6xQ:direct_media_picker_photos_fragment:8,5rG:direct_thread:9",
(
"6xQ:direct_media_picker_photos_fragment:1,5rG:direct_thread:2,"
"5ME:direct_quick_camera_fragment:3,5ME:direct_quick_camera_fragment:4,"
"4ju:reel_composer_preview:5,5rG:direct_thread:6,5rG:direct_thread:7,"
"6xQ:direct_media_picker_photos_fragment:8,5rG:direct_thread:9"
),
(
"1qT:feed_timeline:1,7Az:direct_inbox:2,7Az:direct_inbox:3,"
"5rG:direct_thread:4,6xQ:direct_media_picker_photos_fragment:5,"
"5rG:direct_thread:6,5rG:direct_thread:7,"
"6xQ:direct_media_picker_photos_fragment:8,5rG:direct_thread:9"
),
]
kwargs = {}
data = {
Expand Down Expand Up @@ -512,25 +525,19 @@ def direct_users_presence(self, user_ids: List[int]) -> Dict:
return result

def direct_active_presence(self) -> Dict:
'''
"""
Getting active presences in Direct
Returns
-------
Dict
Dict with active presences
'''
params = {
"recent_thread_limit" : 0,
"suggested_followers_limit" : 100
}
"""
params = {"recent_thread_limit": 0, "suggested_followers_limit": 100}
result = self.private_request(
"direct_v2/get_presence_active_now/",
params=params
"direct_v2/get_presence_active_now/", params=params
)
assert (
result.get("status") == "ok"
), f"Failed to retrieve active presences"
assert result.get("status") == "ok", "Failed to retrieve active presences"

return result.get("user_presence", {})

Expand Down Expand Up @@ -597,8 +604,10 @@ def direct_search(
!= "" # Check to exclude suggestions from FB
]

def direct_message_search(self, query: str) -> List[Tuple[DirectMessage, DirectShortThread]]:
'''
def direct_message_search(
self, query: str
) -> List[Tuple[DirectMessage, DirectShortThread]]:
"""
Search query mentions in direct messages
Parameters
Expand All @@ -610,24 +619,29 @@ def direct_message_search(self, query: str) -> List[Tuple[DirectMessage, DirectS
-------
List[Tuple[DirectMessage, DirectThread]]
List of Tuples with DirectMessage (matched query) and its DirectThread
'''
"""
params = {
"offsets" : '{"message_content":"0","reshared_content":""}',
"query" : query,
"result_types" : '["message_content","reshared_content"]'
"offsets": '{"message_content":"0","reshared_content":""}',
"query": query,
"result_types": '["message_content","reshared_content"]',
}
result = self.private_request(
"direct_v2/search_secondary/",
params=params,
)
assert result.get("status", "") == "ok"
search_results = result.get("message_search_results", {})

data = []
for item in search_results.get("message_search_result_items", []):
message = item.get("matched_message_info", {})
thread = item.get("thread", {})
data.append((extract_direct_message(message.get("item_info", {})), extract_direct_short_thread(thread)))
data.append(
(
extract_direct_message(message.get("item_info", {})),
extract_direct_short_thread(thread),
)
)
return data

def direct_thread_by_participants(self, user_ids: List[int]) -> Dict:
Expand All @@ -652,8 +666,10 @@ def direct_thread_by_participants(self, user_ids: List[int]) -> Dict:
)
users = []
for user in result.get("users", []):
# User dict object also contains fields like follower_count,
# following_count, mutual_followers_count, media_count
users.append(
UserShort( # User dict object also contains fields like follower_count, following_count, mutual_followers_count, media_count
UserShort(
pk=user["pk"],
username=user["username"],
full_name=user["full_name"],
Expand Down Expand Up @@ -713,7 +729,10 @@ def direct_media_share(self, media_id: str, user_ids: List[int]) -> DirectMessag
"client_context": token,
"media_id": media_id,
"mutation_token": token,
"nav_chain": "1VL:feed_timeline:1,1VL:feed_timeline:2,1VL:feed_timeline:5,DirectShareSheetFragment:direct_reshare_sheet:6",
"nav_chain": (
"1VL:feed_timeline:1,1VL:feed_timeline:2,1VL:feed_timeline:5,"
"DirectShareSheetFragment:direct_reshare_sheet:6"
),
"offline_threading_id": token,
}
result = self.private_request(
Expand Down Expand Up @@ -757,7 +776,10 @@ def direct_story_share(
"send_attribution": "reel_feed_timeline",
"client_context": token,
"mutation_token": token,
"nav_chain": "1qT:feed_timeline:1,ReelViewerFragment:reel_feed_timeline:4,DirectShareSheetFragment:direct_reshare_sheet:5",
"nav_chain": (
"1qT:feed_timeline:1,ReelViewerFragment:reel_feed_timeline:4,"
"DirectShareSheetFragment:direct_reshare_sheet:5"
),
"reel_id": story_pk,
"containermodule": "reel_feed_timeline",
"story_media_id": story_id,
Expand Down Expand Up @@ -930,7 +952,10 @@ def direct_profile_share(
"send_attribution": "profile",
"client_context": token,
"mutation_token": token,
"nav_chain": "1qT:feed_timeline:1,ReelViewerFragment:reel_feed_timeline:4,DirectShareSheetFragment:direct_reshare_sheet:5",
"nav_chain": (
"1qT:feed_timeline:1,ReelViewerFragment:reel_feed_timeline:4,"
"DirectShareSheetFragment:direct_reshare_sheet:5"
),
"profile_user_id": user_id,
"offline_threading_id": token,
}
Expand Down
38 changes: 16 additions & 22 deletions instagrapi/mixins/note.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from instagrapi.types import Note


class NoteMixin:
def get_notes(self) -> list[Note]:
'''
"""
Retrieves Notes in Direct
Returns
-------
List[Notes]
List of all the Notes in Direct
'''
"""
result = self.private_request("notes/get_notes/")
assert result.get("status", "") == "ok", "Failed to retrieve Notes in Direct"

Expand All @@ -19,17 +20,16 @@ def get_notes(self) -> list[Note]:
return notes

def last_seen_update_note(self) -> bool:
'''
"""
Updating your Notes last seen
Returns
-------
bool
A boolean value
'''
"""
result = self.private_request(
"notes/update_notes_last_seen_timestamp/",
data={"_uuid" : self.uuid}
"notes/update_notes_last_seen_timestamp/", data={"_uuid": self.uuid}
)
return result.get("status", "") == "ok"

Expand All @@ -48,13 +48,12 @@ def delete_note(self, note_id: int) -> bool:
A boolean value
"""
result = self.private_request(
"notes/delete_note/",
data={"id": note_id, "_uuid": self.uuid}
"notes/delete_note/", data={"id": note_id, "_uuid": self.uuid}
)
return result.get("status", "") == "ok"

def create_note(self, text: str, audience: int = 0) -> Note:
'''
"""
Create personal Note
Parameters
Expand All @@ -69,21 +68,16 @@ def create_note(self, text: str, audience: int = 0) -> Note:
-------
Note
Created Note
'''
"""
assert self.user_id, "Login required"
assert audience in (0, 1), f"Invalid audience parameter={audience} (must be 0 or 1)"
assert audience in (
0,
1,
), f"Invalid audience parameter={audience} (must be 0 or 1)"

data = {
"note_style" : 0,
"text": text,
"_uuid": self.uuid,
"audience": audience
}
result = self.private_request(
"notes/create_note",
data=data
)
data = {"note_style": 0, "text": text, "_uuid": self.uuid, "audience": audience}
result = self.private_request("notes/create_note", data=data)

assert result.pop("status", "") == "ok", "Failed to create new Note"
return Note(**result)
14 changes: 8 additions & 6 deletions instagrapi/mixins/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -1152,9 +1152,11 @@ def close_friend_remove(self, user_id: str):
"add": [],
}
result = self.private_request("friendships/set_besties/", data)
return json_value(result, "friendship_statuses", user_id, "is_bestie") == False
return json_value(result, "friendship_statuses", user_id, "is_bestie") is False

def creator_info(self, user_id: str, entry_point: str = "direct_thread") -> Tuple[UserShort, Dict]:
def creator_info(
self, user_id: str, entry_point: str = "direct_thread"
) -> Tuple[UserShort, Dict]:
"""
Retrieves Creator's information
Expand All @@ -1173,14 +1175,14 @@ def creator_info(self, user_id: str, entry_point: str = "direct_thread") -> Tupl
"""
assert self.user_id, "Login required"
params = {
"entry_point" : entry_point,
"surface_type" : "android",
"user_id" : user_id
"entry_point": entry_point,
"surface_type": "android",
"user_id": user_id,
}

result = self.private_request("creator/creator_info/", params=params)
assert result.get("status", "") == "ok"

creator_info = result.get("user", {}).pop("creator_info", {})
user = extract_user_short(result.get("user", {}))
return (user, creator_info)
return (user, creator_info)
2 changes: 1 addition & 1 deletion instagrapi/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class Media(BaseModel):


class MediaXma(BaseModel):
#media_type: int
# media_type: int
video_url: HttpUrl # for Video and IGTV
title: Optional[str] = ""
preview_url: Optional[HttpUrl]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

setup(
name="instagrapi",
version="1.19.2",
version="1.19.3",
author="Mikhail Andreev",
author_email="[email protected]",
license="MIT",
Expand Down

0 comments on commit 5c22e8f

Please sign in to comment.