Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stories command #49

Merged
merged 2 commits into from
Sep 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 20 additions & 37 deletions src/Osintgram.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ def __printTargetBanner__(self):
else:
pc.printout(" [NOT FOLLOWING]", pc.RED)


print('\n')

def change_target(self):
Expand Down Expand Up @@ -497,7 +496,6 @@ def get_user_info(self):
with open(json_file_name, 'w') as f:
json.dump(user, f)


def get_total_likes(self):
if self.check_private_profile():
return
Expand Down Expand Up @@ -660,19 +658,19 @@ def get_people_who_tagged(self):
users = []

for post in posts:
if not any(u['id'] == post['user']['pk'] for u in users):
user = {
'id': post['user']['pk'],
'username': post['user']['username'],
'full_name': post['user']['full_name'],
'counter': 1
}
users.append(user)
else:
for user in users:
if user['id'] == post['user']['pk']:
user['counter'] += 1
break
if not any(u['id'] == post['user']['pk'] for u in users):
user = {
'id': post['user']['pk'],
'username': post['user']['username'],
'full_name': post['user']['full_name'],
'counter': 1
}
users.append(user)
else:
for user in users:
if user['id'] == post['user']['pk']:
user['counter'] += 1
break

ssort = sorted(users, key=lambda value: value['counter'], reverse=True)

Expand Down Expand Up @@ -844,34 +842,29 @@ def get_user_propic(self):
else:
pc.printout("Sorry! No results found :-(\n", pc.RED)


def get_user_stories(self):
if self.check_private_profile():
return

pc.printout("Searching for target stories...\n")

endpoint = 'feed/user/{id!s}/story/'.format(**{'id': self.target_id})

content = requests.get("https://www.instagram.com/" + endpoint)
data = content.json()
data = self.api.user_reel_media(str(self.target_id))

counter = 0

if data['reel'] is not None: # no stories avaibile
for i in data['reel']['items']:
if data['items'] is not None: # no stories avaibile
counter = data['media_count']
for i in data['items']:
story_id = i["id"]
if i["media_type"] == 1: # it's a photo
url = i['image_versions2']['candidates'][0]['url']
end = "output/" + self.target + "_" + story_id + ".jpg"
urllib.request.urlretrieve(url, end)
counter += 1

elif i["media_type"] == 2: # it's a gif or video
url = i['video_versions'][0]['url']
end = "output/" + self.target + "_" + story_id + ".mp4"
urllib.request.urlretrieve(url, end)
counter += 1

if counter > 0:
pc.printout(str(counter) + " target stories saved in output folder\n", pc.GREEN)
Expand Down Expand Up @@ -972,7 +965,6 @@ def get_user(self, username):

return user


def set_write_file(self, flag):
if flag:
pc.printout("Write to file: ")
Expand Down Expand Up @@ -1011,7 +1003,7 @@ def login(self, u, p):
else:
with open(settings_file) as file_data:
cached_settings = json.load(file_data, object_hook=self.from_json)
#print('Reusing settings: {0!s}'.format(settings_file))
# print('Reusing settings: {0!s}'.format(settings_file))

# reuse auth settings
self.api = AppClient(
Expand All @@ -1028,7 +1020,7 @@ def login(self, u, p):
on_login=lambda x: self.onlogin_callback(x, settings_file))

except ClientError as e:
#pc.printout('ClientError {0!s} (Code: {1:d}, Response: {2!s})'.format(e.msg, e.code, e.error_response), pc.RED)
# pc.printout('ClientError {0!s} (Code: {1:d}, Response: {2!s})'.format(e.msg, e.code, e.error_response), pc.RED)
error = json.loads(e.error_response)
pc.printout(error['message'], pc.RED)
pc.printout("\n")
Expand All @@ -1049,7 +1041,7 @@ def onlogin_callback(self, api, new_settings_file):
cache_settings = api.settings
with open(new_settings_file, 'w') as outfile:
json.dump(cache_settings, outfile, default=self.to_json)
#print('SAVED: {0!s}'.format(new_settings_file))
# print('SAVED: {0!s}'.format(new_settings_file))

def check_following(self):
endpoint = 'users/{user_id!s}/full_detail_info/'.format(**{'user_id': self.target_id})
Expand Down Expand Up @@ -1123,12 +1115,3 @@ def get_fwersemail(self):
print(t)
else:
pc.printout("Sorry! No results found :-(\n", pc.RED)