Projects STRLCPY Osintgram Commits c80f5231
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    changelog.md CHANGELOG.md
    1 1  # Changelog
    2 2   
     3 +## [0.7](https://github.com/Datalux/Osintgram/releases/tag/0.7)
     4 + 
     5 +**Enhancements**
     6 +- banner now show target ID (#30)
     7 +- persistent login (#33)
     8 +- error handler (85e390b)
     9 +- added CTRL+C handler (c2c3c3e)
     10 + 
     11 +**Bug fixes**
     12 +- fix likes and comments posts counter bug (44b7534)
     13 + 
     14 + 
     15 + 
    3 16  ## [0.6](https://github.com/Datalux/Osintgram/releases/tag/0.6)
    4 17   
    5 18  **Enhancements**
    skipped 55 lines
  • ■ ■ ■ ■ ■ ■
    README.md
    1  -[![](https://img.shields.io/badge/version-0.6-green)](https://github.com/Datalux/Osintgram/releases/tag/0.6)
     1 +[![](https://img.shields.io/badge/version-0.7-green)](https://github.com/Datalux/Osintgram/releases/tag/0.7)
    2 2  [![](https://img.shields.io/badge/license-GPLv3-blue)](https://img.shields.io/badge/license-GPLv3-blue)
    3 3  [![](https://img.shields.io/badge/language-Python3-red)](https://img.shields.io/badge/language-Python3-red)
    4 4   
    skipped 25 lines
    30 30  ```
    31 31  You can find detailed commands usage [here](commands.md).
    32 32   
    33  -[**Latest version**](https://github.com/Datalux/Osintgram/releases/tag/0.6) |
    34  -[CHANGELOG](changelog.md)
     33 +[**Latest version**](https://github.com/Datalux/Osintgram/releases/tag/0.7) |
     34 +[CHANGELOG](CHANGELOG.md)
    35 35   
    36 36  ## Tools
    37 37  <p align="center">
    skipped 38 lines
  • ■ ■ ■ ■ ■
    main.py
    skipped 4 lines
    5 5  import argparse
    6 6  from src import printcolors as pc
    7 7  import sys
     8 +import signal
    8 9   
    9 10   
    10 11  def printlogo():
    skipped 4 lines
    15 16   pc.printout("\_______ /____ >__|___| /__| \___ /|__| (____ /__|_| /\n", pc.YELLOW)
    16 17   pc.printout(" \/ \/ \/ /_____/ \/ \/ \n", pc.YELLOW)
    17 18   print('\n')
    18  - pc.printout("Version 0.6 - Developed by Giuseppe Criscione - 2019\n\n", pc.YELLOW)
     19 + pc.printout("Version 0.7 - Developed by Giuseppe Criscione - 2019\n\n", pc.YELLOW)
    19 20   pc.printout("Type 'list' to show all allowed commands\n")
    20 21   pc.printout("Type 'FILE=y' to save results to files like '<target username>_<command>.txt (deafult is disabled)'\n")
    21 22   pc.printout("Type 'FILE=n' to disable saving to files'\n")
    skipped 40 lines
    62 63   pc.printout("wcommented\t")
    63 64   print("Get a list of user who commented target's photos")
    64 65   
     66 + 
     67 +def signal_handler(sig, frame):
     68 + pc.printout("\nGoodbye!\n", pc.RED)
     69 + sys.exit(0)
     70 + 
     71 + 
     72 +signal.signal(signal.SIGINT, signal_handler)
    65 73   
    66 74  printlogo()
    67 75   
    skipped 62 lines
  • ■ ■ ■ ■ ■ ■
    src/Osintgram.py
    skipped 1 lines
    2 2  import json
    3 3  import sys
    4 4  import urllib
     5 +import os
     6 +import codecs
    5 7   
    6 8  from geopy.geocoders import Nominatim
    7 9  from instagram_private_api import Client as AppClient
     10 +from instagram_private_api import ClientCookieExpiredError, ClientLoginRequiredError, ClientError
     11 + 
    8 12  from prettytable import PrettyTable
    9 13   
    10 14  from src import printcolors as pc
    skipped 14 lines
    25 29   u = self.__getUsername__()
    26 30   p = self.__getPassword__()
    27 31   print("\nAttempt to login...")
    28  - self.api = AppClient(auto_patch=True, authenticate=True, username=u, password=p)
     32 + self.login(u, p)
    29 33   self.setTarget(target)
    30 34   self.writeFile = is_file
    31 35   self.jsonDump = is_json
    skipped 56 lines
    88 92   def __printTargetBanner__(self):
    89 93   pc.printout("\nLogged as ", pc.GREEN)
    90 94   pc.printout(self.api.username, pc.CYAN)
    91  - pc.printout(" (" + str(self.api.authenticated_user_id) + ") ")
    92  - pc.printout("target: ", pc.GREEN)
     95 + pc.printout(". Target: ", pc.GREEN)
    93 96   pc.printout(str(self.target), pc.CYAN)
    94  - pc.printout(" (private: " + str(self.is_private) + ")")
     97 + pc.printout(" [" + str(self.target_id) + "] ")
     98 + if self.is_private:
     99 + pc.printout("[PRIVATE PROFILE]", pc.RED)
    95 100   print('\n')
    96 101   
    97 102   def change_target(self):
    skipped 142 lines
    240 245   
    241 246   for post in data:
    242 247   comments_counter += post['comment_count']
     248 + posts += 1
    243 249   
    244 250   if self.writeFile:
    245 251   file_name = "output/" + self.target + "_comments.txt"
    skipped 242 lines
    488 494   
    489 495   for post in data:
    490 496   like_counter += post['like_count']
     497 + posts += 1
    491 498   
    492 499   if self.writeFile:
    493 500   file_name = "output/" + self.target + "_likes.txt"
    skipped 414 lines
    908 915   
    909 916   self.jsonDump = flag
    910 917   
     918 + def login(self, u, p):
     919 + try:
     920 + settings_file = "config/settings.json"
     921 + if not os.path.isfile(settings_file):
     922 + # settings file does not exist
     923 + print('Unable to find file: {0!s}'.format(settings_file))
     924 + 
     925 + # login new
     926 + self.api = AppClient(auto_patch=True, authenticate=True, username=u, password=p,
     927 + on_login=lambda x: self.onlogin_callback(x, settings_file))
     928 + 
     929 + else:
     930 + with open(settings_file) as file_data:
     931 + cached_settings = json.load(file_data, object_hook=self.from_json)
     932 + #print('Reusing settings: {0!s}'.format(settings_file))
     933 + 
     934 + # reuse auth settings
     935 + self.api = AppClient(
     936 + username=u, password=p,
     937 + settings=cached_settings,
     938 + on_login=lambda x: self.onlogin_callback(x, settings_file))
     939 + 
     940 + except (ClientCookieExpiredError, ClientLoginRequiredError) as e:
     941 + print('ClientCookieExpiredError/ClientLoginRequiredError: {0!s}'.format(e))
     942 + 
     943 + # Login expired
     944 + # Do relogin but use default ua, keys and such
     945 + self.api = AppClient(auto_patch=True, authenticate=True, username=u, password=p,
     946 + on_login=lambda x: self.onlogin_callback(x, settings_file))
     947 + 
     948 + except ClientError as e:
     949 + #pc.printout('ClientError {0!s} (Code: {1:d}, Response: {2!s})'.format(e.msg, e.code, e.error_response), pc.RED)
     950 + error = json.loads(e.error_response)
     951 + pc.printout(error['message'], pc.RED)
     952 + pc.printout("\n")
     953 + exit(9)
     954 + 
     955 + def to_json(self, python_object):
     956 + if isinstance(python_object, bytes):
     957 + return {'__class__': 'bytes',
     958 + '__value__': codecs.encode(python_object, 'base64').decode()}
     959 + raise TypeError(repr(python_object) + ' is not JSON serializable')
     960 + 
     961 + def from_json(self, json_object):
     962 + if '__class__' in json_object and json_object['__class__'] == 'bytes':
     963 + return codecs.decode(json_object['__value__'].encode(), 'base64')
     964 + return json_object
     965 + 
     966 + def onlogin_callback(self, api, new_settings_file):
     967 + cache_settings = api.settings
     968 + with open(new_settings_file, 'w') as outfile:
     969 + json.dump(cache_settings, outfile, default=self.to_json)
     970 + #print('SAVED: {0!s}'.format(new_settings_file))
     971 + 
Please wait...
Page is in error, reload to recover