-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'Story Reel' and 'Story' endpoints
- Loading branch information
Showing
12 changed files
with
182 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from sys import argv | ||
from context import Instpector, endpoints | ||
|
||
def get_story_reel(**options): | ||
|
||
instpector = Instpector() | ||
if not instpector.login(user=options.get("user"), password=options.get("password")): | ||
return | ||
|
||
profile = endpoints.factory.create("profile", instpector) | ||
story_reel = endpoints.factory.create("story_reel", instpector) | ||
story = endpoints.factory.create("story", instpector) | ||
|
||
target_profile = profile.of_user(options.get("target_username")) | ||
|
||
for story_item in story_reel.of_user(target_profile.id): | ||
print(story_item.view_count) | ||
for viewer in story.viewers_for(story_item.id): | ||
print(viewer.username) | ||
|
||
instpector.logout() | ||
|
||
if __name__ == '__main__': | ||
if len(argv) < 6: | ||
print(( | ||
"Missing arguments: " | ||
"--user {user} " | ||
"--password {password} " | ||
"--target_username {username}" | ||
)) | ||
exit(1) | ||
get_story_reel( | ||
user=argv[2], | ||
password=argv[4], | ||
target_username=argv[6] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from .base_graph_ql import BaseGraphQL | ||
from .parser import Parser | ||
|
||
|
||
class Story(BaseGraphQL): | ||
|
||
def viewers_for(self, item_id): | ||
variables = { | ||
"item_id": item_id, | ||
"story_viewer_fetch_count": 50, | ||
"story_viewer_cursor": "0" | ||
} | ||
return self._loop("42c6ec100f5e57a1fe09be16cd3a7021", | ||
variables=variables, | ||
page_info_parser="edge_story_media_viewers", | ||
page_info_parser_path="media", | ||
page_info_next_cursor="story_viewer_cursor", | ||
data_parser=Parser.story) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import json | ||
from ..exceptions import ParseDataException | ||
from .base_api import BaseApi | ||
from .parser import Parser | ||
|
||
|
||
class StoryReel(BaseApi): | ||
|
||
def __init__(self, browser_session): | ||
super().__init__("https://www.instagram.com", browser_session) | ||
|
||
def of_user(self, user_id): | ||
params = { | ||
"query_hash": "cda12de4f7fd3719c0569ce03589f4c4", | ||
"variables": json.dumps({ | ||
"reel_ids": [user_id], | ||
"tag_names": [], | ||
"location_ids": [], | ||
"highlight_reel_ids": [], | ||
"precomposed_overlay": False, | ||
"show_story_viewer_list": True, | ||
"story_viewer_fetch_count": 50, | ||
"story_viewer_cursor": "", | ||
"stories_video_dash_manifest": False | ||
}) | ||
} | ||
try: | ||
data = super().get(f"/graphql/query/", params=params, headers={ | ||
"DNT": "1" | ||
}) | ||
if data: | ||
return Parser.story_reel(data) | ||
except ParseDataException: | ||
print(f"Invalid story reel data for user id {user_id}") | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters