@@ -17,21 +17,24 @@ class Osintgram:
17
17
geolocator = Nominatim ()
18
18
user_id = None
19
19
target_id = None
20
+ is_private = True
20
21
target = ""
21
22
writeFile = False
22
23
23
24
def __init__ (self , target ):
24
25
u = self .__getUsername__ ()
25
26
p = self .__getPassword__ ()
26
27
self .api = InstagramAPI (u , p )
27
- print ("\n Attempt to login...\n " )
28
+ print ("\n Attempt to login..." )
28
29
self .api .login ()
29
30
self .setTarget (target )
30
31
31
32
32
33
def setTarget (self , target ):
33
34
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' ]
35
38
self .__printTargetBanner__ ()
36
39
37
40
@@ -87,11 +90,12 @@ def __getAdressesTimes__(self, id):
87
90
return sort_addresses
88
91
89
92
def __printTargetBanner__ (self ):
90
- pc .printout ("Logged as " , pc .GREEN )
93
+ pc .printout ("\n Logged as " , pc .GREEN )
91
94
pc .printout (self .api .username , pc .CYAN )
92
95
pc .printout (" (" + str (self .api .username_id ) + ") " )
93
96
pc .printout ("target: " , pc .GREEN )
94
97
pc .printout (str (self .target ), pc .CYAN )
98
+ pc .printout (" (private: " + str (self .is_private ) + ")" )
95
99
print ('\n ' )
96
100
97
101
def setWriteFile (self , bool ):
@@ -347,6 +351,10 @@ def getPeopleTaggedByUser(self):
347
351
348
352
349
353
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
+
350
358
pc .printout ("Searching for target address... this may take a few minutes...\n " )
351
359
addrs = self .__getAdressesTimes__ (self .target_id )
352
360
t = PrettyTable ()
@@ -371,6 +379,10 @@ def getAddrs(self):
371
379
print (t )
372
380
373
381
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
+
374
386
pc .printout ("Searching for target followers...\n " )
375
387
376
388
followers = self .__getTotalFollowers__ (self .target_id )
@@ -391,6 +403,10 @@ def getFollowers(self):
391
403
print (t )
392
404
393
405
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
+
394
410
pc .printout ("Searching for target followings...\n " )
395
411
396
412
followings = self .__getUserFollowigs__ (self .target_id )
@@ -410,7 +426,7 @@ def getFollowings(self):
410
426
411
427
print (t )
412
428
413
- def getUserID (self , username ):
429
+ def getUser (self , username ):
414
430
try :
415
431
content = urllib .request .urlopen ("https://www.instagram.com/" + username + "/?__a=1" )
416
432
except urllib .error .HTTPError as err :
@@ -425,7 +441,12 @@ def getUserID(self, username):
425
441
file = open (file_name , "w" )
426
442
file .write (str (data ['graphql' ]['user' ]['id' ]))
427
443
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
429
450
430
451
def getUserInfo (self ):
431
452
try :
@@ -456,8 +477,11 @@ def getUserInfo(self):
456
477
pc .printout ("[VERIFIED ACCOUNT] " , pc .CYAN )
457
478
pc .printout (str (data ['is_verified' ]) + '\n ' )
458
479
459
-
460
480
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
+
461
485
content = self .api .SendRequest2 (self .target + '/?__a=1' )
462
486
data = self .api .LastJson
463
487
dd = data ['graphql' ]['user' ]['edge_owner_to_timeline_media' ]['edges' ]
@@ -487,8 +511,11 @@ def getPhotoDescription(self):
487
511
else :
488
512
pc .printout ("Sorry! No results found :-(\n " , pc .RED )
489
513
490
-
491
514
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
+
492
519
limit = - 1
493
520
pc .printout ("How many photos you want to download (default all): " , pc .YELLOW )
494
521
l = input ()
@@ -556,8 +583,11 @@ def getUserPhoto(self):
556
583
557
584
pc .printout ("\n Woohoo! We downloaded " + str (counter ) + " photos (saved in output/ folder) \n " , pc .GREEN )
558
585
559
-
560
586
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
+
561
591
pc .printout ("Searching for target captions...\n " )
562
592
563
593
a = None
@@ -616,8 +646,11 @@ def getCaptions(self):
616
646
617
647
return
618
648
619
-
620
649
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
+
621
654
pc .printout ("Searching for target captions...\n " )
622
655
623
656
a = None
@@ -677,8 +710,6 @@ def getMediaType(self):
677
710
pc .printout ("Sorry! No results found :-(\n " , pc .RED )
678
711
679
712
return
680
-
681
-
682
713
683
714
def getUserPropic (self ):
684
715
try :
@@ -706,8 +737,11 @@ def getUserPropic(self):
706
737
else :
707
738
pc .printout ("Sorry! No results found :-(\n " , pc .RED )
708
739
709
-
710
740
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
+
711
745
pc .printout ("Searching for target stories...\n " )
712
746
713
747
endpoint = 'feed/user/{id!s}/story/' .format (** {'id' : self .target_id })
@@ -735,7 +769,6 @@ def getUserStories(self):
735
769
else :
736
770
pc .printout ("Sorry! No results found :-(\n " , pc .RED )
737
771
738
-
739
772
def changeTarget (self ):
740
773
pc .printout ("Insert new target username: " , pc .YELLOW )
741
774
l = input ()
0 commit comments