■ ■ ■ ■ ■ ■
src/commands/propic/run.py
| 1 | + | from prettytable import PrettyTable |
| 2 | + | from src import printcolors as pc |
| 3 | + | import sys |
| 4 | + | import time |
| 5 | + | import urllib |
| 6 | + | from instagram_private_api import ClientError |
| 7 | + | |
| 8 | + | |
| 9 | + | from src.CommandFather import CommandFather |
| 10 | + | |
| 11 | + | |
| 12 | + | class Command(CommandFather): |
| 13 | + | |
| 14 | + | def __init__(self, status, api): |
| 15 | + | super().__init__(status) |
| 16 | + | self.status = status |
| 17 | + | self.osintgram = api |
| 18 | + | |
| 19 | + | def run(self): |
| 20 | + | try: |
| 21 | + | super().create_folder_if_not_exists() |
| 22 | + | |
| 23 | + | endpoint = 'users/{user_id!s}/full_detail_info/'.format(**{'user_id': self.osintgram.target_id}) |
| 24 | + | content = self.osintgram.get_api()._call_api(endpoint) |
| 25 | + | |
| 26 | + | data = content['user_detail']['user'] |
| 27 | + | |
| 28 | + | if "hd_profile_pic_url_info" in data: |
| 29 | + | URL = data["hd_profile_pic_url_info"]['url'] |
| 30 | + | else: |
| 31 | + | #get better quality photo |
| 32 | + | items = len(data['hd_profile_pic_versions']) |
| 33 | + | URL = data["hd_profile_pic_versions"][items-1]['url'] |
| 34 | + | |
| 35 | + | if URL != "": |
| 36 | + | end = super().get_option('output_path') + "/" + self.osintgram.target + "_propic.jpg" |
| 37 | + | urllib.request.urlretrieve(URL, end) |
| 38 | + | pc.printout("Target propic saved in output folder\n", pc.GREEN) |
| 39 | + | |
| 40 | + | else: |
| 41 | + | pc.printout("Sorry! No results found :-(\n", pc.RED) |
| 42 | + | |
| 43 | + | except ClientError as e: |
| 44 | + | error = json.loads(e.error_response) |
| 45 | + | print(error['message']) |
| 46 | + | print(error['error_title']) |
| 47 | + | self.status.release() |
| 48 | + | |