Skip to content

Commit 9140290

Browse files
authored
Merge pull request #10 from Datalux/fix/private-profile
feat: add private profile check
2 parents e100909 + 348f7ac commit 9140290

File tree

1 file changed

+46
-13
lines changed

1 file changed

+46
-13
lines changed

Osintgram.py

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,24 @@ class Osintgram:
1717
geolocator = Nominatim()
1818
user_id = None
1919
target_id = None
20+
is_private = True
2021
target = ""
2122
writeFile = False
2223

2324
def __init__(self, target):
2425
u = self.__getUsername__()
2526
p = self.__getPassword__()
2627
self.api = InstagramAPI(u, p)
27-
print("\nAttempt to login...\n")
28+
print("\nAttempt to login...")
2829
self.api.login()
2930
self.setTarget(target)
3031

3132

3233
def setTarget(self, target):
3334
self.target = target
34-
self.target_id = self.getUserID(target)
35+
user = self.getUser(target)
36+
self.target_id = user['id']
37+
self.is_private = user['is_private']
3538
self.__printTargetBanner__()
3639

3740

@@ -87,11 +90,12 @@ def __getAdressesTimes__(self, id):
8790
return sort_addresses
8891

8992
def __printTargetBanner__(self):
90-
pc.printout("Logged as ", pc.GREEN)
93+
pc.printout("\nLogged as ", pc.GREEN)
9194
pc.printout(self.api.username, pc.CYAN)
9295
pc.printout(" (" + str(self.api.username_id) + ") ")
9396
pc.printout("target: ", pc.GREEN)
9497
pc.printout(str(self.target), pc.CYAN)
98+
pc.printout(" (private: " + str(self.is_private) + ")")
9599
print('\n')
96100

97101
def setWriteFile(self, bool):
@@ -347,6 +351,10 @@ def getPeopleTaggedByUser(self):
347351

348352

349353
def getAddrs(self):
354+
if(self.is_private):
355+
pc.printout("Impossible to execute command: user has private profile\n", pc.RED)
356+
return
357+
350358
pc.printout("Searching for target address... this may take a few minutes...\n")
351359
addrs = self.__getAdressesTimes__(self.target_id)
352360
t = PrettyTable()
@@ -371,6 +379,10 @@ def getAddrs(self):
371379
print(t)
372380

373381
def getFollowers(self):
382+
if(self.is_private):
383+
pc.printout("Impossible to execute command: user has private profile\n", pc.RED)
384+
return
385+
374386
pc.printout("Searching for target followers...\n")
375387

376388
followers = self.__getTotalFollowers__(self.target_id)
@@ -391,6 +403,10 @@ def getFollowers(self):
391403
print(t)
392404

393405
def getFollowings(self):
406+
if(self.is_private):
407+
pc.printout("Impossible to execute command: user has private profile\n", pc.RED)
408+
return
409+
394410
pc.printout("Searching for target followings...\n")
395411

396412
followings = self.__getUserFollowigs__(self.target_id)
@@ -410,7 +426,7 @@ def getFollowings(self):
410426

411427
print(t)
412428

413-
def getUserID(self, username):
429+
def getUser(self, username):
414430
try:
415431
content = urllib.request.urlopen("https://www.instagram.com/" + username + "/?__a=1" )
416432
except urllib.error.HTTPError as err:
@@ -425,7 +441,12 @@ def getUserID(self, username):
425441
file = open(file_name, "w")
426442
file.write(str(data['graphql']['user']['id']))
427443
file.close()
428-
return data['graphql']['user']['id']
444+
445+
user = dict()
446+
user['id'] = data['graphql']['user']['id']
447+
user['is_private'] = data['graphql']['user']['is_private']
448+
449+
return user
429450

430451
def getUserInfo(self):
431452
try:
@@ -456,8 +477,11 @@ def getUserInfo(self):
456477
pc.printout("[VERIFIED ACCOUNT] ", pc.CYAN)
457478
pc.printout(str(data['is_verified']) + '\n')
458479

459-
460480
def getPhotoDescription(self):
481+
if(self.is_private):
482+
pc.printout("Impossible to execute command: user has private profile\n", pc.RED)
483+
return
484+
461485
content = self.api.SendRequest2(self.target + '/?__a=1')
462486
data = self.api.LastJson
463487
dd = data['graphql']['user']['edge_owner_to_timeline_media']['edges']
@@ -487,8 +511,11 @@ def getPhotoDescription(self):
487511
else:
488512
pc.printout("Sorry! No results found :-(\n", pc.RED)
489513

490-
491514
def getUserPhoto(self):
515+
if(self.is_private):
516+
pc.printout("Impossible to execute command: user has private profile\n", pc.RED)
517+
return
518+
492519
limit = -1
493520
pc.printout("How many photos you want to download (default all): ", pc.YELLOW)
494521
l = input()
@@ -556,8 +583,11 @@ def getUserPhoto(self):
556583

557584
pc.printout("\nWoohoo! We downloaded " + str(counter) + " photos (saved in output/ folder) \n", pc.GREEN)
558585

559-
560586
def getCaptions(self):
587+
if(self.is_private):
588+
pc.printout("Impossible to execute command: user has private profile\n", pc.RED)
589+
return
590+
561591
pc.printout("Searching for target captions...\n")
562592

563593
a = None
@@ -616,8 +646,11 @@ def getCaptions(self):
616646

617647
return
618648

619-
620649
def getMediaType(self):
650+
if(self.is_private):
651+
pc.printout("Impossible to execute command: user has private profile\n", pc.RED)
652+
return
653+
621654
pc.printout("Searching for target captions...\n")
622655

623656
a = None
@@ -677,8 +710,6 @@ def getMediaType(self):
677710
pc.printout("Sorry! No results found :-(\n", pc.RED)
678711

679712
return
680-
681-
682713

683714
def getUserPropic(self):
684715
try:
@@ -706,8 +737,11 @@ def getUserPropic(self):
706737
else:
707738
pc.printout("Sorry! No results found :-(\n", pc.RED)
708739

709-
710740
def getUserStories(self):
741+
if(self.is_private):
742+
pc.printout("Impossible to execute command: user has private profile\n", pc.RED)
743+
return
744+
711745
pc.printout("Searching for target stories...\n")
712746

713747
endpoint = 'feed/user/{id!s}/story/'.format(**{'id': self.target_id})
@@ -735,7 +769,6 @@ def getUserStories(self):
735769
else:
736770
pc.printout("Sorry! No results found :-(\n", pc.RED)
737771

738-
739772
def changeTarget(self):
740773
pc.printout("Insert new target username: ", pc.YELLOW)
741774
l = input()

0 commit comments

Comments
 (0)