Class to be instantiated to use the script
| 105 | |
| 106 | |
| 107 | class InstaPy: |
| 108 | """Class to be instantiated to use the script""" |
| 109 | |
| 110 | def __init__( |
| 111 | self, |
| 112 | username: str = None, |
| 113 | password: str = None, |
| 114 | nogui: bool = False, |
| 115 | selenium_local_session: bool = True, |
| 116 | browser_profile_path: str = None, |
| 117 | page_delay: int = 25, |
| 118 | show_logs: bool = True, |
| 119 | headless_browser: bool = False, |
| 120 | proxy_username: str = None, |
| 121 | proxy_password: str = None, |
| 122 | proxy_address: str = None, |
| 123 | proxy_port: str = None, |
| 124 | disable_image_load: bool = False, |
| 125 | multi_logs: bool = True, |
| 126 | log_handler=None, # TODO function type ? |
| 127 | geckodriver_path: str = None, |
| 128 | split_db: bool = False, |
| 129 | bypass_security_challenge_using: str = "email", |
| 130 | security_codes: int = 0000, |
| 131 | want_check_browser: bool = True, |
| 132 | browser_executable_path: str = None, |
| 133 | geckodriver_log_level: str = "info", # "info" by default |
| 134 | ): |
| 135 | print("InstaPy Version: {}".format(__version__)) |
| 136 | cli_args = parse_cli_args() |
| 137 | username = cli_args.username or username |
| 138 | password = cli_args.password or password |
| 139 | page_delay = cli_args.page_delay or page_delay |
| 140 | headless_browser = cli_args.headless_browser or headless_browser |
| 141 | proxy_address = cli_args.proxy_address or proxy_address |
| 142 | proxy_port = cli_args.proxy_port or proxy_port |
| 143 | disable_image_load = cli_args.disable_image_load or disable_image_load |
| 144 | split_db = cli_args.split_db or split_db |
| 145 | want_check_browser = cli_args.want_check_browser or want_check_browser |
| 146 | |
| 147 | Settings.InstaPy_is_running = True |
| 148 | # workspace must be ready before anything |
| 149 | if not get_workspace(): |
| 150 | raise InstaPyError("Oh no! I don't have a workspace to work at :'(") |
| 151 | |
| 152 | # virtual display to hide browser (not supported on Windows) |
| 153 | self.nogui = nogui |
| 154 | if self.nogui: |
| 155 | if not platform.startswith("win32"): |
| 156 | self.display = Display(visible=0, size=(800, 600)) |
| 157 | self.display.start() |
| 158 | else: |
| 159 | raise InstaPyError("The 'nogui' parameter isn't supported on Windows.") |
| 160 | |
| 161 | self.browser = None |
| 162 | self.page_delay = page_delay |
| 163 | self.disable_image_load = disable_image_load |
| 164 | self.bypass_security_challenge_using = bypass_security_challenge_using |