| skipped 3 lines |
4 | 4 | | import urllib |
5 | 5 | | import os |
6 | 6 | | import codecs |
| 7 | + | from pathlib import Path |
7 | 8 | | |
8 | 9 | | import requests |
9 | 10 | | import ssl |
| skipped 20 lines |
30 | 31 | | target = "" |
31 | 32 | | writeFile = False |
32 | 33 | | jsonDump = False |
| 34 | + | cli_mode = False |
| 35 | + | output_dir = "output" |
33 | 36 | | |
34 | | - | def __init__(self, target, is_file, is_json): |
| 37 | + | |
| 38 | + | def __init__(self, target, is_file, is_json, is_cli, output_dir, clear_cookies): |
| 39 | + | self.output_dir = output_dir or self.output_dir |
| 40 | + | Path(self.output_dir).mkdir(parents=True, exist_ok=True) |
35 | 41 | | u = config.getUsername() |
36 | 42 | | p = config.getPassword() |
37 | | - | print("\nAttempt to login...") |
| 43 | + | self.clear_cookies(clear_cookies) |
| 44 | + | self.cli_mode = is_cli |
| 45 | + | if not is_cli: |
| 46 | + | print("\nAttempt to login...") |
38 | 47 | | self.login(u, p) |
39 | 48 | | self.setTarget(target) |
40 | 49 | | self.writeFile = is_file |
41 | 50 | | self.jsonDump = is_json |
42 | 51 | | |
| 52 | + | def clear_cookies(self,clear_cookies): |
| 53 | + | if clear_cookies: |
| 54 | + | self.clear_cache() |
| 55 | + | |
43 | 56 | | def setTarget(self, target): |
44 | 57 | | self.target = target |
45 | 58 | | user = self.get_user(target) |
| skipped 103 lines |
149 | 162 | | i = i + 1 |
150 | 163 | | |
151 | 164 | | if self.writeFile: |
152 | | - | file_name = "output/" + self.target + "_addrs.txt" |
| 165 | + | file_name = self.output_dir + "/" + self.target + "_addrs.txt" |
153 | 166 | | file = open(file_name, "w") |
154 | 167 | | file.write(str(t)) |
155 | 168 | | file.close() |
156 | 169 | | |
157 | 170 | | if self.jsonDump: |
158 | 171 | | json_data['address'] = addrs_list |
159 | | - | json_file_name = "output/" + self.target + "_addrs.json" |
| 172 | + | json_file_name = self.output_dir + "/" + self.target + "_addrs.json" |
160 | 173 | | with open(json_file_name, 'w') as f: |
161 | 174 | | json.dump(json_data, f) |
162 | 175 | | |
| skipped 36 lines |
199 | 212 | | file = None |
200 | 213 | | |
201 | 214 | | if self.writeFile: |
202 | | - | file_name = "output/" + self.target + "_captions.txt" |
| 215 | + | file_name = self.output_dir + "/" + self.target + "_captions.txt" |
203 | 216 | | file = open(file_name, "w") |
204 | 217 | | |
205 | 218 | | for s in captions: |
| skipped 4 lines |
210 | 223 | | |
211 | 224 | | if self.jsonDump: |
212 | 225 | | json_data['captions'] = captions |
213 | | - | json_file_name = "output/" + self.target + "_followings.json" |
| 226 | + | json_file_name = self.output_dir + "/" + self.target + "_followings.json" |
214 | 227 | | with open(json_file_name, 'w') as f: |
215 | 228 | | json.dump(json_data, f) |
216 | 229 | | |
| skipped 21 lines |
238 | 251 | | posts += 1 |
239 | 252 | | |
240 | 253 | | if self.writeFile: |
241 | | - | file_name = "output/" + self.target + "_comments.txt" |
| 254 | + | file_name = self.output_dir + "/" + self.target + "_comments.txt" |
242 | 255 | | file = open(file_name, "w") |
243 | 256 | | file.write(str(comments_counter) + " comments in " + str(posts) + " posts\n") |
244 | 257 | | file.close() |
| skipped 3 lines |
248 | 261 | | 'comment_counter': comments_counter, |
249 | 262 | | 'posts': posts |
250 | 263 | | } |
251 | | - | json_file_name = "output/" + self.target + "_comments.json" |
| 264 | + | json_file_name = self.output_dir + "/" + self.target + "_comments.json" |
252 | 265 | | with open(json_file_name, 'w') as f: |
253 | 266 | | json.dump(json_data, f) |
254 | 267 | | |
| skipped 29 lines |
284 | 297 | | |
285 | 298 | | print(t) |
286 | 299 | | if self.writeFile: |
287 | | - | file_name = "output/" + self.target + "_comment_data.txt" |
| 300 | + | file_name = self.output_dir + "/" + self.target + "_comment_data.txt" |
288 | 301 | | with open(file_name, 'w') as f: |
289 | 302 | | f.write(str(t)) |
290 | 303 | | f.close() |
291 | 304 | | |
292 | 305 | | if self.jsonDump: |
293 | | - | file_name_json = "output/" + self.target + "_comment_data.json" |
| 306 | + | file_name_json = self.output_dir + "/" + self.target + "_comment_data.json" |
294 | 307 | | with open(file_name_json, 'w') as f: |
295 | 308 | | f.write("{ \"Comments\":[ \n") |
296 | 309 | | f.write('\n'.join(json.dumps(comment) for comment in _comments) + ',\n') |
| skipped 53 lines |
350 | 363 | | followings_list.append(follow) |
351 | 364 | | |
352 | 365 | | if self.writeFile: |
353 | | - | file_name = "output/" + self.target + "_followers.txt" |
| 366 | + | file_name = self.output_dir + "/" + self.target + "_followers.txt" |
354 | 367 | | file = open(file_name, "w") |
355 | 368 | | file.write(str(t)) |
356 | 369 | | file.close() |
357 | 370 | | |
358 | 371 | | if self.jsonDump: |
359 | 372 | | json_data['followers'] = followers |
360 | | - | json_file_name = "output/" + self.target + "_followers.json" |
| 373 | + | json_file_name = self.output_dir + "/" + self.target + "_followers.json" |
361 | 374 | | with open(json_file_name, 'w') as f: |
362 | 375 | | json.dump(json_data, f) |
363 | 376 | | |
| skipped 51 lines |
415 | 428 | | followings_list.append(follow) |
416 | 429 | | |
417 | 430 | | if self.writeFile: |
418 | | - | file_name = "output/" + self.target + "_followings.txt" |
| 431 | + | file_name = self.output_dir + "/" + self.target + "_followings.txt" |
419 | 432 | | file = open(file_name, "w") |
420 | 433 | | file.write(str(t)) |
421 | 434 | | file.close() |
422 | 435 | | |
423 | 436 | | if self.jsonDump: |
424 | 437 | | json_data['followings'] = followings_list |
425 | | - | json_file_name = "output/" + self.target + "_followings.json" |
| 438 | + | json_file_name = self.output_dir + "/" + self.target + "_followings.json" |
426 | 439 | | with open(json_file_name, 'w') as f: |
427 | 440 | | json.dump(json_data, f) |
428 | 441 | | |
| skipped 42 lines |
471 | 484 | | hashtags_list = [] |
472 | 485 | | |
473 | 486 | | if self.writeFile: |
474 | | - | file_name = "output/" + self.target + "_hashtags.txt" |
| 487 | + | file_name = self.output_dir + "/" + self.target + "_hashtags.txt" |
475 | 488 | | file = open(file_name, "w") |
476 | 489 | | |
477 | 490 | | for k, v in ssort: |
| skipped 9 lines |
487 | 500 | | |
488 | 501 | | if self.jsonDump: |
489 | 502 | | json_data['hashtags'] = hashtags_list |
490 | | - | json_file_name = "output/" + self.target + "_hashtags.json" |
| 503 | + | json_file_name = self.output_dir + "/" + self.target + "_hashtags.json" |
491 | 504 | | with open(json_file_name, 'w') as f: |
492 | 505 | | json.dump(json_data, f) |
493 | 506 | | else: |
| skipped 52 lines |
546 | 559 | | 'biography': data['biography'], |
547 | 560 | | 'edge_followed_by': data['follower_count'], |
548 | 561 | | 'edge_follow': data['following_count'], |
549 | | - | 'is_business_account': data['is_business_account'], |
550 | | - | 'is_verified': data['is_business'], |
| 562 | + | 'is_business_account': data['is_business'], |
| 563 | + | 'is_verified': data['is_verified'], |
551 | 564 | | 'profile_pic_url_hd': data['hd_profile_pic_url_info']['url'] |
552 | 565 | | } |
553 | 566 | | if 'public_email' in data and data['public_email']: |
| skipped 9 lines |
563 | 576 | | if 'contact_phone_number' in data and data['contact_phone_number']: |
564 | 577 | | user['contact_phone_number'] = data['contact_phone_number'] |
565 | 578 | | |
566 | | - | json_file_name = "output/" + self.target + "_info.json" |
| 579 | + | json_file_name = self.output_dir + "/" + self.target + "_info.json" |
567 | 580 | | with open(json_file_name, 'w') as f: |
568 | 581 | | json.dump(user, f) |
569 | 582 | | |
| skipped 19 lines |
589 | 602 | | posts += 1 |
590 | 603 | | |
591 | 604 | | if self.writeFile: |
592 | | - | file_name = "output/" + self.target + "_likes.txt" |
| 605 | + | file_name = self.output_dir + "/" + self.target + "_likes.txt" |
593 | 606 | | file = open(file_name, "w") |
594 | 607 | | file.write(str(like_counter) + " likes in " + str(like_counter) + " posts\n") |
595 | 608 | | file.close() |
| skipped 3 lines |
599 | 612 | | 'like_counter': like_counter, |
600 | 613 | | 'posts': like_counter |
601 | 614 | | } |
602 | | - | json_file_name = "output/" + self.target + "_likes.json" |
| 615 | + | json_file_name = self.output_dir + "/" + self.target + "_likes.json" |
603 | 616 | | with open(json_file_name, 'w') as f: |
604 | 617 | | json.dump(json_data, f) |
605 | 618 | | |
| skipped 28 lines |
634 | 647 | | if counter > 0: |
635 | 648 | | |
636 | 649 | | if self.writeFile: |
637 | | - | file_name = "output/" + self.target + "_mediatype.txt" |
| 650 | + | file_name = self.output_dir + "/" + self.target + "_mediatype.txt" |
638 | 651 | | file = open(file_name, "w") |
639 | 652 | | file.write(str(photo_counter) + " photos and " + str(video_counter) + " video posted by target\n") |
640 | 653 | | file.close() |
| skipped 6 lines |
647 | 660 | | "photos": photo_counter, |
648 | 661 | | "videos": video_counter |
649 | 662 | | } |
650 | | - | json_file_name = "output/" + self.target + "_mediatype.json" |
| 663 | + | json_file_name = self.output_dir + "/" + self.target + "_mediatype.json" |
651 | 664 | | with open(json_file_name, 'w') as f: |
652 | 665 | | json.dump(json_data, f) |
653 | 666 | | |
| skipped 45 lines |
699 | 712 | | print(t) |
700 | 713 | | |
701 | 714 | | if self.writeFile: |
702 | | - | file_name = "output/" + self.target + "_users_who_commented.txt" |
| 715 | + | file_name = self.output_dir + "/" + self.target + "_users_who_commented.txt" |
703 | 716 | | file = open(file_name, "w") |
704 | 717 | | file.write(str(t)) |
705 | 718 | | file.close() |
706 | 719 | | |
707 | 720 | | if self.jsonDump: |
708 | 721 | | json_data['users_who_commented'] = ssort |
709 | | - | json_file_name = "output/" + self.target + "_users_who_commented.json" |
| 722 | + | json_file_name = self.output_dir + "/" + self.target + "_users_who_commented.json" |
710 | 723 | | with open(json_file_name, 'w') as f: |
711 | 724 | | json.dump(json_data, f) |
712 | 725 | | else: |
| skipped 54 lines |
767 | 780 | | print(t) |
768 | 781 | | |
769 | 782 | | if self.writeFile: |
770 | | - | file_name = "output/" + self.target + "_users_who_tagged.txt" |
| 783 | + | file_name = self.output_dir + "/" + self.target + "_users_who_tagged.txt" |
771 | 784 | | file = open(file_name, "w") |
772 | 785 | | file.write(str(t)) |
773 | 786 | | file.close() |
774 | 787 | | |
775 | 788 | | if self.jsonDump: |
776 | 789 | | json_data['users_who_tagged'] = ssort |
777 | | - | json_file_name = "output/" + self.target + "_users_who_tagged.json" |
| 790 | + | json_file_name = self.output_dir + "/" + self.target + "_users_who_tagged.json" |
778 | 791 | | with open(json_file_name, 'w') as f: |
779 | 792 | | json.dump(json_data, f) |
780 | 793 | | else: |
| skipped 34 lines |
815 | 828 | | count += 1 |
816 | 829 | | |
817 | 830 | | if self.writeFile: |
818 | | - | file_name = "output/" + self.target + "_photodes.txt" |
| 831 | + | file_name = self.output_dir + "/" + self.target + "_photodes.txt" |
819 | 832 | | file = open(file_name, "w") |
820 | 833 | | file.write(str(t)) |
821 | 834 | | file.close() |
822 | 835 | | |
823 | 836 | | if self.jsonDump: |
824 | 837 | | json_data['descriptions'] = descriptions_list |
825 | | - | json_file_name = "output/" + self.target + "_descriptions.json" |
| 838 | + | json_file_name = self.output_dir + "/" + self.target + "_descriptions.json" |
826 | 839 | | with open(json_file_name, 'w') as f: |
827 | 840 | | json.dump(json_data, f) |
828 | 841 | | |
| skipped 6 lines |
835 | 848 | | return |
836 | 849 | | |
837 | 850 | | limit = -1 |
838 | | - | pc.printout("How many photos you want to download (default all): ", pc.YELLOW) |
839 | | - | user_input = input() |
| 851 | + | if self.cli_mode: |
| 852 | + | user_input = "" |
| 853 | + | else: |
| 854 | + | pc.printout("How many photos you want to download (default all): ", pc.YELLOW) |
| 855 | + | user_input = input() |
| 856 | + | |
840 | 857 | | try: |
841 | 858 | | if user_input == "": |
842 | 859 | | pc.printout("Downloading all photos available...\n") |
| skipped 25 lines |
868 | 885 | | counter = counter + 1 |
869 | 886 | | url = item["image_versions2"]["candidates"][0]["url"] |
870 | 887 | | photo_id = item["id"] |
871 | | - | end = "output/" + self.target + "_" + photo_id + ".jpg" |
| 888 | + | end = self.output_dir + "/" + self.target + "_" + photo_id + ".jpg" |
872 | 889 | | urllib.request.urlretrieve(url, end) |
873 | 890 | | sys.stdout.write("\rDownloaded %i" % counter) |
874 | 891 | | sys.stdout.flush() |
| skipped 5 lines |
880 | 897 | | counter = counter + 1 |
881 | 898 | | url = i["image_versions2"]["candidates"][0]["url"] |
882 | 899 | | photo_id = i["id"] |
883 | | - | end = "output/" + self.target + "_" + photo_id + ".jpg" |
| 900 | + | end = self.output_dir + "/" + self.target + "_" + photo_id + ".jpg" |
884 | 901 | | urllib.request.urlretrieve(url, end) |
885 | 902 | | sys.stdout.write("\rDownloaded %i" % counter) |
886 | 903 | | sys.stdout.flush() |
| skipped 7 lines |
894 | 911 | | sys.stdout.write(" photos") |
895 | 912 | | sys.stdout.flush() |
896 | 913 | | |
897 | | - | pc.printout("\nWoohoo! We downloaded " + str(counter) + " photos (saved in output/ folder) \n", pc.GREEN) |
| 914 | + | pc.printout("\nWoohoo! We downloaded " + str(counter) + " photos (saved in " + self.output_dir + " folder) \n", pc.GREEN) |
898 | 915 | | |
899 | 916 | | def get_user_propic(self): |
900 | 917 | | |
| skipped 11 lines |
912 | 929 | | URL = data["hd_profile_pic_versions"][items-1]['url'] |
913 | 930 | | |
914 | 931 | | if URL != "": |
915 | | - | end = "output/" + self.target + "_propic.jpg" |
| 932 | + | end = self.output_dir + "/" + self.target + "_propic.jpg" |
916 | 933 | | urllib.request.urlretrieve(URL, end) |
917 | 934 | | pc.printout("Target propic saved in output folder\n", pc.GREEN) |
918 | 935 | | |
| skipped 22 lines |
941 | 958 | | story_id = i["id"] |
942 | 959 | | if i["media_type"] == 1: # it's a photo |
943 | 960 | | url = i['image_versions2']['candidates'][0]['url'] |
944 | | - | end = "output/" + self.target + "_" + story_id + ".jpg" |
| 961 | + | end = self.output_dir + "/" + self.target + "_" + story_id + ".jpg" |
945 | 962 | | urllib.request.urlretrieve(url, end) |
946 | 963 | | |
947 | 964 | | elif i["media_type"] == 2: # it's a gif or video |
948 | 965 | | url = i['video_versions'][0]['url'] |
949 | | - | end = "output/" + self.target + "_" + story_id + ".mp4" |
| 966 | + | end = self.output_dir + "/" + self.target + "_" + story_id + ".mp4" |
950 | 967 | | urllib.request.urlretrieve(url, end) |
951 | 968 | | |
952 | 969 | | if counter > 0: |
| skipped 59 lines |
1012 | 1029 | | tagged_list.append(tag) |
1013 | 1030 | | |
1014 | 1031 | | if self.writeFile: |
1015 | | - | file_name = "output/" + self.target + "_tagged.txt" |
| 1032 | + | file_name = self.output_dir + "/" + self.target + "_tagged.txt" |
1016 | 1033 | | file = open(file_name, "w") |
1017 | 1034 | | file.write(str(t)) |
1018 | 1035 | | file.close() |
1019 | 1036 | | |
1020 | 1037 | | if self.jsonDump: |
1021 | 1038 | | json_data['tagged'] = tagged_list |
1022 | | - | json_file_name = "output/" + self.target + "_tagged.json" |
| 1039 | + | json_file_name = self.output_dir + "/" + self.target + "_tagged.json" |
1023 | 1040 | | with open(json_file_name, 'w') as f: |
1024 | 1041 | | json.dump(json_data, f) |
1025 | 1042 | | |
| skipped 5 lines |
1031 | 1048 | | try: |
1032 | 1049 | | content = self.api.username_info(username) |
1033 | 1050 | | if self.writeFile: |
1034 | | - | file_name = "output/" + self.target + "_user_id.txt" |
| 1051 | + | file_name = self.output_dir + "/" + self.target + "_user_id.txt" |
1035 | 1052 | | file = open(file_name, "w") |
1036 | 1053 | | file.write(str(content['user']['pk'])) |
1037 | 1054 | | file.close() |
| skipped 4 lines |
1042 | 1059 | | |
1043 | 1060 | | return user |
1044 | 1061 | | except ClientError as e: |
| 1062 | + | pc.printout('ClientError {0!s} (Code: {1:d}, Response: {2!s})'.format(e.msg, e.code, e.error_response), pc.RED) |
1045 | 1063 | | error = json.loads(e.error_response) |
1046 | 1064 | | if 'message' in error: |
1047 | 1065 | | print(error['message']) |
| skipped 59 lines |
1107 | 1125 | | on_login=lambda x: self.onlogin_callback(x, settings_file)) |
1108 | 1126 | | |
1109 | 1127 | | except ClientError as e: |
1110 | | - | #pc.printout('ClientError {0!s} (Code: {1:d}, Response: {2!s})'.format(e.msg, e.code, e.error_response), pc.RED) |
| 1128 | + | pc.printout('ClientError {0!s} (Code: {1:d}, Response: {2!s})'.format(e.msg, e.code, e.error_response), pc.RED) |
1111 | 1129 | | error = json.loads(e.error_response) |
1112 | 1130 | | pc.printout(error['message'], pc.RED) |
1113 | 1131 | | pc.printout(": ", pc.RED) |
| skipped 78 lines |
1192 | 1210 | | |
1193 | 1211 | | results = [] |
1194 | 1212 | | |
| 1213 | + | pc.printout("Do you want to get all emails? y/n: ", pc.YELLOW) |
| 1214 | + | value = input() |
| 1215 | + | |
| 1216 | + | if value == str("y") or value == str("yes") or value == str("Yes") or value == str("YES"): |
| 1217 | + | value = len(followers) |
| 1218 | + | elif value == str(""): |
| 1219 | + | print("\n") |
| 1220 | + | return |
| 1221 | + | elif value == str("n") or value == str("no") or value == str("No") or value == str("NO"): |
| 1222 | + | while True: |
| 1223 | + | try: |
| 1224 | + | pc.printout("How many emails do you want to get? ", pc.YELLOW) |
| 1225 | + | new_value = int(input()) |
| 1226 | + | value = new_value - 1 |
| 1227 | + | break |
| 1228 | + | except ValueError: |
| 1229 | + | pc.printout("Error! Please enter a valid integer!", pc.RED) |
| 1230 | + | print("\n") |
| 1231 | + | return |
| 1232 | + | else: |
| 1233 | + | pc.printout("Error! Please enter y/n :-)", pc.RED) |
| 1234 | + | print("\n") |
| 1235 | + | return |
| 1236 | + | |
1195 | 1237 | | for follow in followers: |
1196 | 1238 | | user = self.api.user_info(str(follow['id'])) |
1197 | 1239 | | if 'public_email' in user['user'] and user['user']['public_email']: |
1198 | 1240 | | follow['email'] = user['user']['public_email'] |
| 1241 | + | if len(results) > value: |
| 1242 | + | break |
1199 | 1243 | | results.append(follow) |
1200 | 1244 | | |
1201 | 1245 | | except ClientThrottledError as e: |
1202 | 1246 | | pc.printout("\nError: Instagram blocked the requests. Please wait a few minutes before you try again.", pc.RED) |
1203 | 1247 | | pc.printout("\n") |
1204 | | - | return |
1205 | 1248 | | |
1206 | 1249 | | if len(results) > 0: |
1207 | 1250 | | |
| skipped 9 lines |
1217 | 1260 | | t.add_row([str(node['id']), node['username'], node['full_name'], node['email']]) |
1218 | 1261 | | |
1219 | 1262 | | if self.writeFile: |
1220 | | - | file_name = "output/" + self.target + "_fwersemail.txt" |
| 1263 | + | file_name = self.output_dir + "/" + self.target + "_fwersemail.txt" |
1221 | 1264 | | file = open(file_name, "w") |
1222 | 1265 | | file.write(str(t)) |
1223 | 1266 | | file.close() |
1224 | 1267 | | |
1225 | 1268 | | if self.jsonDump: |
1226 | 1269 | | json_data['followers_email'] = results |
1227 | | - | json_file_name = "output/" + self.target + "_fwersemail.json" |
| 1270 | + | json_file_name = self.output_dir + "/" + self.target + "_fwersemail.json" |
1228 | 1271 | | with open(json_file_name, 'w') as f: |
1229 | 1272 | | json.dump(json_data, f) |
1230 | 1273 | | |
| skipped 39 lines |
1270 | 1313 | | |
1271 | 1314 | | results = [] |
1272 | 1315 | | |
| 1316 | + | pc.printout("Do you want to get all emails? y/n: ", pc.YELLOW) |
| 1317 | + | value = input() |
| 1318 | + | |
| 1319 | + | if value == str("y") or value == str("yes") or value == str("Yes") or value == str("YES"): |
| 1320 | + | value = len(followings) |
| 1321 | + | elif value == str(""): |
| 1322 | + | print("\n") |
| 1323 | + | return |
| 1324 | + | elif value == str("n") or value == str("no") or value == str("No") or value == str("NO"): |
| 1325 | + | while True: |
| 1326 | + | try: |
| 1327 | + | pc.printout("How many emails do you want to get? ", pc.YELLOW) |
| 1328 | + | new_value = int(input()) |
| 1329 | + | value = new_value - 1 |
| 1330 | + | break |
| 1331 | + | except ValueError: |
| 1332 | + | pc.printout("Error! Please enter a valid integer!", pc.RED) |
| 1333 | + | print("\n") |
| 1334 | + | return |
| 1335 | + | else: |
| 1336 | + | pc.printout("Error! Please enter y/n :-)", pc.RED) |
| 1337 | + | print("\n") |
| 1338 | + | return |
| 1339 | + | |
1273 | 1340 | | for follow in followings: |
1274 | 1341 | | sys.stdout.write("\rCatched %i followings email" % len(results)) |
1275 | 1342 | | sys.stdout.flush() |
1276 | 1343 | | user = self.api.user_info(str(follow['id'])) |
1277 | 1344 | | if 'public_email' in user['user'] and user['user']['public_email']: |
1278 | 1345 | | follow['email'] = user['user']['public_email'] |
| 1346 | + | if len(results) > value: |
| 1347 | + | break |
1279 | 1348 | | results.append(follow) |
1280 | 1349 | | |
1281 | 1350 | | except ClientThrottledError as e: |
1282 | 1351 | | pc.printout("\nError: Instagram blocked the requests. Please wait a few minutes before you try again.", pc.RED) |
1283 | 1352 | | pc.printout("\n") |
1284 | | - | return |
1285 | 1353 | | |
1286 | 1354 | | print("\n") |
1287 | 1355 | | |
| skipped 10 lines |
1298 | 1366 | | t.add_row([str(node['id']), node['username'], node['full_name'], node['email']]) |
1299 | 1367 | | |
1300 | 1368 | | if self.writeFile: |
1301 | | - | file_name = "output/" + self.target + "_fwingsemail.txt" |
| 1369 | + | file_name = self.output_dir + "/" + self.target + "_fwingsemail.txt" |
1302 | 1370 | | file = open(file_name, "w") |
1303 | 1371 | | file.write(str(t)) |
1304 | 1372 | | file.close() |
1305 | 1373 | | |
1306 | 1374 | | if self.jsonDump: |
1307 | 1375 | | json_data['followings_email'] = results |
1308 | | - | json_file_name = "output/" + self.target + "_fwingsemail.json" |
| 1376 | + | json_file_name = self.output_dir + "/" + self.target + "_fwingsemail.json" |
1309 | 1377 | | with open(json_file_name, 'w') as f: |
1310 | 1378 | | json.dump(json_data, f) |
1311 | 1379 | | |
| skipped 39 lines |
1351 | 1419 | | |
1352 | 1420 | | results = [] |
1353 | 1421 | | |
| 1422 | + | pc.printout("Do you want to get all phone numbers? y/n: ", pc.YELLOW) |
| 1423 | + | value = input() |
| 1424 | + | |
| 1425 | + | if value == str("y") or value == str("yes") or value == str("Yes") or value == str("YES"): |
| 1426 | + | value = len(followings) |
| 1427 | + | elif value == str(""): |
| 1428 | + | print("\n") |
| 1429 | + | return |
| 1430 | + | elif value == str("n") or value == str("no") or value == str("No") or value == str("NO"): |
| 1431 | + | while True: |
| 1432 | + | try: |
| 1433 | + | pc.printout("How many phone numbers do you want to get? ", pc.YELLOW) |
| 1434 | + | new_value = int(input()) |
| 1435 | + | value = new_value - 1 |
| 1436 | + | break |
| 1437 | + | except ValueError: |
| 1438 | + | pc.printout("Error! Please enter a valid integer!", pc.RED) |
| 1439 | + | print("\n") |
| 1440 | + | return |
| 1441 | + | else: |
| 1442 | + | pc.printout("Error! Please enter y/n :-)", pc.RED) |
| 1443 | + | print("\n") |
| 1444 | + | return |
| 1445 | + | |
1354 | 1446 | | for follow in followings: |
1355 | 1447 | | sys.stdout.write("\rCatched %i followings phone numbers" % len(results)) |
1356 | 1448 | | sys.stdout.flush() |
1357 | 1449 | | user = self.api.user_info(str(follow['id'])) |
1358 | 1450 | | if 'contact_phone_number' in user['user'] and user['user']['contact_phone_number']: |
1359 | 1451 | | follow['contact_phone_number'] = user['user']['contact_phone_number'] |
| 1452 | + | if len(results) > value: |
| 1453 | + | break |
1360 | 1454 | | results.append(follow) |
1361 | 1455 | | |
1362 | 1456 | | except ClientThrottledError as e: |
1363 | 1457 | | pc.printout("\nError: Instagram blocked the requests. Please wait a few minutes before you try again.", pc.RED) |
1364 | 1458 | | pc.printout("\n") |
1365 | | - | return |
1366 | 1459 | | |
1367 | 1460 | | print("\n") |
1368 | 1461 | | |
| skipped 10 lines |
1379 | 1472 | | t.add_row([str(node['id']), node['username'], node['full_name'], node['contact_phone_number']]) |
1380 | 1473 | | |
1381 | 1474 | | if self.writeFile: |
1382 | | - | file_name = "output/" + self.target + "_fwingsnumber.txt" |
| 1475 | + | file_name = self.output_dir + "/" + self.target + "_fwingsnumber.txt" |
1383 | 1476 | | file = open(file_name, "w") |
1384 | 1477 | | file.write(str(t)) |
1385 | 1478 | | file.close() |
1386 | 1479 | | |
1387 | 1480 | | if self.jsonDump: |
1388 | 1481 | | json_data['followings_phone_numbers'] = results |
1389 | | - | json_file_name = "output/" + self.target + "_fwingsnumber.json" |
| 1482 | + | json_file_name = self.output_dir + "/" + self.target + "_fwingsnumber.json" |
1390 | 1483 | | with open(json_file_name, 'w') as f: |
1391 | 1484 | | json.dump(json_data, f) |
1392 | 1485 | | |
| skipped 40 lines |
1433 | 1526 | | |
1434 | 1527 | | results = [] |
1435 | 1528 | | |
| 1529 | + | pc.printout("Do you want to get all phone numbers? y/n: ", pc.YELLOW) |
| 1530 | + | value = input() |
| 1531 | + | |
| 1532 | + | if value == str("y") or value == str("yes") or value == str("Yes") or value == str("YES"): |
| 1533 | + | value = len(followings) |
| 1534 | + | elif value == str(""): |
| 1535 | + | print("\n") |
| 1536 | + | return |
| 1537 | + | elif value == str("n") or value == str("no") or value == str("No") or value == str("NO"): |
| 1538 | + | while True: |
| 1539 | + | try: |
| 1540 | + | pc.printout("How many phone numbers do you want to get? ", pc.YELLOW) |
| 1541 | + | new_value = int(input()) |
| 1542 | + | value = new_value - 1 |
| 1543 | + | break |
| 1544 | + | except ValueError: |
| 1545 | + | pc.printout("Error! Please enter a valid integer!", pc.RED) |
| 1546 | + | print("\n") |
| 1547 | + | return |
| 1548 | + | else: |
| 1549 | + | pc.printout("Error! Please enter y/n :-)", pc.RED) |
| 1550 | + | print("\n") |
| 1551 | + | return |
| 1552 | + | |
1436 | 1553 | | for follow in followings: |
1437 | 1554 | | sys.stdout.write("\rCatched %i followers phone numbers" % len(results)) |
1438 | 1555 | | sys.stdout.flush() |
1439 | 1556 | | user = self.api.user_info(str(follow['id'])) |
1440 | 1557 | | if 'contact_phone_number' in user['user'] and user['user']['contact_phone_number']: |
1441 | 1558 | | follow['contact_phone_number'] = user['user']['contact_phone_number'] |
| 1559 | + | if len(results) > value: |
| 1560 | + | break |
1442 | 1561 | | results.append(follow) |
1443 | 1562 | | |
1444 | 1563 | | except ClientThrottledError as e: |
1445 | 1564 | | pc.printout("\nError: Instagram blocked the requests. Please wait a few minutes before you try again.", pc.RED) |
1446 | 1565 | | pc.printout("\n") |
1447 | | - | return |
1448 | 1566 | | |
1449 | 1567 | | print("\n") |
1450 | 1568 | | |
| skipped 10 lines |
1461 | 1579 | | t.add_row([str(node['id']), node['username'], node['full_name'], node['contact_phone_number']]) |
1462 | 1580 | | |
1463 | 1581 | | if self.writeFile: |
1464 | | - | file_name = "output/" + self.target + "_fwersnumber.txt" |
| 1582 | + | file_name = self.output_dir + "/" + self.target + "_fwersnumber.txt" |
1465 | 1583 | | file = open(file_name, "w") |
1466 | 1584 | | file.write(str(t)) |
1467 | 1585 | | file.close() |
1468 | 1586 | | |
1469 | 1587 | | if self.jsonDump: |
1470 | 1588 | | json_data['followings_phone_numbers'] = results |
1471 | | - | json_file_name = "output/" + self.target + "_fwerssnumber.json" |
| 1589 | + | json_file_name = self.output_dir + "/" + self.target + "_fwerssnumber.json" |
1472 | 1590 | | with open(json_file_name, 'w') as f: |
1473 | 1591 | | json.dump(json_data, f) |
1474 | 1592 | | |
| skipped 48 lines |
1523 | 1641 | | print(t) |
1524 | 1642 | | |
1525 | 1643 | | if self.writeFile: |
1526 | | - | file_name = "output/" + self.target + "_users_who_commented.txt" |
| 1644 | + | file_name = self.output_dir + "/" + self.target + "_users_who_commented.txt" |
1527 | 1645 | | file = open(file_name, "w") |
1528 | 1646 | | file.write(str(t)) |
1529 | 1647 | | file.close() |
1530 | 1648 | | |
1531 | 1649 | | if self.jsonDump: |
1532 | 1650 | | json_data['users_who_commented'] = ssort |
1533 | | - | json_file_name = "output/" + self.target + "_users_who_commented.json" |
| 1651 | + | json_file_name = self.output_dir + "/" + self.target + "_users_who_commented.json" |
1534 | 1652 | | with open(json_file_name, 'w') as f: |
1535 | 1653 | | json.dump(json_data, f) |
1536 | 1654 | | else: |
1537 | 1655 | | pc.printout("Sorry! No results found :-(\n", pc.RED) |
1538 | 1656 | | |
| 1657 | + | def clear_cache(self): |
| 1658 | + | try: |
| 1659 | + | f = open("config/settings.json",'w') |
| 1660 | + | f.write("{}") |
| 1661 | + | pc.printout("Cache Cleared.\n",pc.GREEN) |
| 1662 | + | except FileNotFoundError: |
| 1663 | + | pc.printout("Settings.json don't exist.\n",pc.RED) |
| 1664 | + | finally: |
| 1665 | + | f.close() |
| 1666 | + | |