Skip to content

Commit

Permalink
v1.10.6
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwickerhf committed Nov 17, 2020
1 parent e6e64f6 commit 8e4a652
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
24 changes: 12 additions & 12 deletions instaclient/client/instaclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def wrapper(self, *args, **kwargs):
return wrapper

# INIT
def __init__(self, driver_type: int=CHROMEDRIVER, host_type:int=LOCAHOST, driver_path=None, init_driver=True, debug=False, error_callback=None, localhost_headless=False):
def __init__(self, driver_type: int=CHROMEDRIVER, host_type:int=LOCAHOST, driver_path=None, init_driver=False, debug=False, error_callback=None, localhost_headless=False):
"""
Create an `InstaClient` object to access the instagram website.
Expand Down Expand Up @@ -215,10 +215,10 @@ def login(self, username:str, password:str, check_user:bool=True, discard_driver
# Detect Suspicious Login Attempt Dialogue
send_code = self.__check_existence(EC.presence_of_element_located((By.XPATH, Paths.SEND_CODE)))
if send_code:
self.logger.debug('INSTACLIENT: Suspicious Login Attempt.')
self.logger.warn('INSTACLIENT: Suspicious Login Attempt.')
send_code = self.__find_element(EC.presence_of_element_located((By.XPATH, Paths.SEND_CODE)), wait_time=4)
self.__press_button(send_code)
self.logger.debug('INSTACLIENT: Sent Security Code')
self.logger.warn('INSTACLIENT: Sent Security Code')
# Detect Error
alert = self.__check_existence(EC.presence_of_element_located((By.XPATH, Paths.ERROR_SENDING_CODE)), wait_time=2)
if alert:
Expand All @@ -227,15 +227,15 @@ def login(self, username:str, password:str, check_user:bool=True, discard_driver
self.__press_button(email)
time.sleep(0.5)
self.__press_button(send_code)
self.logger.debug('INSTACLIENT: Sending code via email')
self.logger.warn('INSTACLIENT: Sending code via email')
raise SuspisciousLoginAttemptError(mode=SuspisciousLoginAttemptError.EMAIL)
raise SuspisciousLoginAttemptError(mode=SuspisciousLoginAttemptError.PHONE)

# Detect 2FS
scode_input = self.__check_existence(EC.presence_of_element_located((By.XPATH, Paths.VERIFICATION_CODE)))
if scode_input:
# 2F Auth is enabled, request security code
self.logger.debug('INSTACLIENT: 2FA Required. Check Auth App')
self.logger.warn('INSTACLIENT: 2FA Required. Check Auth App')
raise VerificationCodeNecessary()
else:
self.logged_in = True
Expand Down Expand Up @@ -292,7 +292,7 @@ def resend_security_code(self):
raise SuspisciousLoginAttemptError(mode)
raise SuspisciousLoginAttemptError()
else:
self.logger.debug('Wrong Url when resending code')
self.logger.warn('Wrong Url when resending code')
return False


Expand Down Expand Up @@ -421,7 +421,7 @@ def is_valid_user(self, user:str, nav_to_user:bool=True, discard_driver:bool=Fal
if self.driver.current_url != ClientUrls.NAV_USER.format(user):
self.driver.get(ClientUrls.NAV_USER.format(user))

self.logger.debug('INSTACLIENT: Url: ', self.driver.current_url)
self.logger.debug('INSTACLIENT: Url: {}'.format(self.driver.current_url))
if self.driver.current_url == ClientUrls.LOGIN_THEN_USER.format(user):
raise NotLoggedInError()
elif self.driver.current_url != ClientUrls.NAV_USER.format(user):
Expand Down Expand Up @@ -669,7 +669,7 @@ def like_latest_posts(self, user:str, n_posts:int, like:bool=True, discard_drive
try:
self.driver.find_element_by_xpath("//*[@aria-label='{}']".format(action)).click()
except Exception as e:
self.logger.debug(e)
self.logger.error(e)

self.driver.find_elements_by_class_name('ckWGn')[0].click()

Expand Down Expand Up @@ -697,7 +697,7 @@ def send_dm(self, user:str, message:str, discard_driver:bool=False):
except Exception as error:
if self.debug:
self.error_callback(self.driver)
self.logger.debug('INSTACLIENT: An error occured when sending a DM to the user <{}>'.format(user))
self.logger.error('INSTACLIENT: An error occured when sending a DM to the user <{}>'.format(user))
raise error


Expand Down Expand Up @@ -956,15 +956,15 @@ def __detect_restriction(self):
"""
restriction = self.__check_existence(EC.presence_of_element_located((By.XPATH, Paths.RESTRICTION_DIALOG)), wait_time=1.2)
if restriction:
self.logger.debug('INSTACLIENT: WARNING: ACCOUNT <{}> HAS BEEN RESTRICTED'.format(self.username))
self.logger.warn('INSTACLIENT: WARNING: ACCOUNT <{}> HAS BEEN RESTRICTED'.format(self.username))
buttons = self.__find_element(EC.presence_of_element_located((By.XPATH, Paths.RESTRICTION_DIALOGUE_BTNS)), retry=False)
buttons.click()
time.sleep(randrange(2,4))
raise RestrictedAccountError(self.username)

block = self.__check_existence(EC.presence_of_element_located((By.XPATH, Paths.BLOCK_DIV)), wait_time=1.2)
if block:
self.logger.debug('INSTACLIENT: WARNING: ACCOUNT <{}> HAS BEEN BLOCKED - Log in Manually'.format(self.username))
self.logger.warn('INSTACLIENT: WARNING: ACCOUNT <{}> HAS BEEN BLOCKED - Log in Manually'.format(self.username))
raise BlockedAccountError(self.username)


Expand Down Expand Up @@ -1021,4 +1021,4 @@ def __init_driver(self, login=False, retries=0, func=None):
try:
self.login(self.username, self.password)
except:
raise InstaClientError(message='Tried self.logger in when initiating driver, but username and password are not defined.')
raise InstaClientError(message='Tried logging in when initiating driver, but username and password are not defined.')
21 changes: 11 additions & 10 deletions instaclient/utilities/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ def get_logger():
logger:logging.Log: Log object
"""

logger = logging.getLogger('INSTACLIENT')
logger.setLevel(logging.DEBUG)
c_handler = logging.StreamHandler()
c_format = logging.Formatter('%(name)s - %(levelname)s - %(message)s')

# log format
c_handler.setFormatter(c_format)

logger.addHandler(c_handler)
return logger
loglevel = logging.INFO
l = logging.getLogger(__name__)
if not getattr(l, 'handler_set', None):
l.setLevel(loglevel)
h = logging.StreamHandler()
f = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
h.setFormatter(f)
l.addHandler(h)
l.setLevel(loglevel)
l.handler_set = True
return l


def exception(func):
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from distutils.core import setup
from setuptools import find_packages
from distutils.core import setup
import pathlib

# The directory containing this file
Expand All @@ -11,15 +11,15 @@
setup(
name = 'instaclient', # How you named your package folder (MyLib)
packages = find_packages(exclude=['tests, drivers']), # Chose the same as "name"
version = '1.10.5', # Start with a small number and increase it with every change you make
version = '1.10.6', # Start with a small number and increase it with every change you make
license='MIT', # Chose a license from here: https://help.github.com/articles/licensing-a-repository
description = 'Instagram client built with Python 3.8 and the Selenium package.',
long_description=README,
long_description_content_type="text/markdown",
author = 'David Wicker', # Type in your name
author_email = 'davidwickerhf@gmail.com', # Type in your E-Mail
url = 'https://github.com/wickerdevs/py-instaclient', # Provide either the link to your github or to your website
download_url = 'https://github.com/wickerdevs/py-instaclient/archive/v1.10.5.tar.gz', # I explain this later on
download_url = 'https://github.com/wickerdevs/py-instaclient/archive/v1.10.6.tar.gz', # I explain this later on
keywords = ['INSTAGRAM', 'BOT', 'INSTAGRAM BOT', 'INSTAGRAM CLIENT'], # Keywords that define your package best
install_requires=[ # I get to this in a second
'selenium',
Expand Down

0 comments on commit 8e4a652

Please sign in to comment.