From 05dc04d68d5bb4310205ecd39c9b9ed3cd2fd970 Mon Sep 17 00:00:00 2001 From: Tomas Alabes Date: Sun, 12 Apr 2020 11:09:15 -0700 Subject: [PATCH 1/2] prefix secrets dir with base_path --- instabot/api/api.py | 12 +++++++----- instabot/api/prepare.py | 27 +++++++++++++++++---------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/instabot/api/api.py b/instabot/api/api.py index 3c25c8b32..f5a931e42 100644 --- a/instabot/api/api.py +++ b/instabot/api/api.py @@ -250,7 +250,9 @@ def login( is_threaded=False, ): if password is None: - username, password = get_credentials(username=username) + username, password = get_credentials( + base_path=self.base_path, username=username + ) set_device = generate_all_uuids = True self.set_user(username, password) @@ -352,7 +354,7 @@ def login( "Failed to login go to instagram and change your password" ) self.save_failed_login() - delete_credentials() + delete_credentials(self.base_path) return False def two_factor_auth(self): @@ -402,7 +404,7 @@ def save_successful_login(self): def save_failed_login(self): self.logger.info("Username or password is incorrect.") - delete_credentials() + delete_credentials(self.base_path) sys.exit() def solve_challenge(self): @@ -588,7 +590,7 @@ def send_request( self.logger.error( "Since we hit 15 minutes of time outs, we have to restart. Removing session and cookies. Please relogin." ) - delete_credentials() + delete_credentials(self.base_path) sys.exit() timeout_minutes += 5 self.logger.warning( @@ -612,7 +614,7 @@ def send_request( self.logger.error( "Failed to login go to instagram and change your password" ) - delete_credentials() + delete_credentials(self.base_path) # PERFORM Interactive Two-Factor Authentication if response_data.get("two_factor_required"): try: diff --git a/instabot/api/prepare.py b/instabot/api/prepare.py index 4124ef3c7..3105c9c17 100644 --- a/instabot/api/prepare.py +++ b/instabot/api/prepare.py @@ -4,11 +4,15 @@ import os import sys -current_path = os.path.abspath(os.getcwd()) -SECRET_FILE = current_path + "/config/secret.txt" +DEFAULT_SECRET_DIR = os.path.abspath(os.getcwd()) -def add_credentials(): +def get_credential_file(base_path=DEFAULT_SECRET_DIR): + return base_path + "/config/secret.txt" + + +def add_credentials(base_path): + SECRET_FILE = get_credential_file(base_path) with open(SECRET_FILE, "a") as f: print("Enter your login: ") f.write(str(sys.stdin.readline().strip()) + ":") @@ -19,7 +23,8 @@ def add_credentials(): f.write(getpass.getpass() + "\n") -def get_credentials(username=None): +def get_credentials(base_path, username=None): + SECRET_FILE = get_credential_file(base_path) """Returns login and password stored in `secret.txt`.""" while not check_secret(): pass @@ -42,11 +47,11 @@ def get_credentials(username=None): try: ind = int(sys.stdin.readline()) if ind == 0: - add_credentials() + add_credentials(base_path) continue elif ind == -1: - delete_credentials() - check_secret() + delete_credentials(base_path) + check_secret(base_path) continue elif 0 <= ind - 1 < len(lines): return lines[ind - 1] @@ -54,7 +59,8 @@ def get_credentials(username=None): print("Wrong input, enter the number of the account to use.") -def check_secret(): +def check_secret(base_path): + SECRET_FILE = get_credential_file(base_path) while True: if os.path.exists(SECRET_FILE): with open(SECRET_FILE, "r") as f: @@ -80,13 +86,14 @@ def check_secret(): ) print("Don't worry. It will be stored locally.") while True: - add_credentials() + add_credentials(base_path) print("Do you want to add another account? (y/n)") if "y" not in sys.stdin.readline(): break -def delete_credentials(): +def delete_credentials(base_path): + SECRET_FILE = get_credential_file(base_path) if os.path.exists(SECRET_FILE): os.remove(SECRET_FILE) From e96371732db4213f97d3f66de0bebc8f0066f470 Mon Sep 17 00:00:00 2001 From: Tomas Alabes Date: Sun, 12 Apr 2020 11:31:38 -0700 Subject: [PATCH 2/2] bot_checkpoint revert --- instabot/bot/bot_checkpoint.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/instabot/bot/bot_checkpoint.py b/instabot/bot/bot_checkpoint.py index cfd2c6704..69e4cf2a6 100644 --- a/instabot/bot/bot_checkpoint.py +++ b/instabot/bot/bot_checkpoint.py @@ -6,8 +6,7 @@ import pickle from datetime import datetime -current_path = os.path.abspath(os.getcwd()) -CHECKPOINT_PATH = current_path + "/config/{fname}.checkpoint" +CHECKPOINT_PATH = "config/{fname}.checkpoint" class Checkpoint(object):