def verify_code(): if request.method == "POST": code = request.form['userLoginPassword'] instagram_username = session["username"]["username"] cl_obj = client.get(instagram_username) api_obj = cl_obj["api"] resp = api_obj.two_factor_auth_remodified(code, api_obj) if resp: import time api_obj.is_logged_in = True api_obj.last_login = time.time() client.set(instagram_username, cl_obj) resp2 = api_obj.login_flow(True) if resp2: user = Users.query.filter_by( insta_username=instagram_username).first() login_user(user=user) return redirect(url_for('users.accept')) else: print("here") return redirect(url_for('core.index')) # return render_template("index.html", page="index", errors="Wrong Code", **default_args) else: print("here1") return redirect(url_for('core.index')) # return render_template("index.html", page="index", errors="Wrong Code", **default_args) elif request.method == "GET": return render_template('verify_code.html')
def index(): if request.method == "POST": instagram_username = request.form['userEmailID'] instagram_password = request.form['userLoginPassword'] instagram_username = instagram_username.lower() session["username"] = {} session["username"]["singleton"] = True session["username"]["username"] = instagram_username session["counter_id"] = instagram_username + CONSTANT.ALL_INFO.value is_subscription_check = check_subscription(instagram_username) if not is_subscription_check: session["message"] = "Please subscribe to login" return redirect(url_for('core.pricing')) bot_obj = bot() resp = bot_obj.login(username=instagram_username, password=instagram_password, ask_for_code=True) cl_obj = client.get(instagram_username) print(resp) if cl_obj.get("bot_obj"): client.set(instagram_username, cl_obj) else: cl_obj["bot_obj"] = bot_obj client.set(instagram_username, cl_obj) if resp == "906": return redirect(url_for('core.verify_code')) if resp != True: return render_template("index.html", page="index", errors=mappings[resp], **default_args) else: user = Users.query.filter_by( insta_username=instagram_username).first() login_user(user=user) print(user.is_authenticated()) return redirect(url_for('users.accept')) elif request.method == "GET": try: if current_user.is_authenticated: instagram_username = current_user.insta_username client.delete(instagram_username) session.clear() logout_user() client.delete(current_user) session.clear() except: pass return render_template('index.html', page="index", errors=[], **default_args, current_user=current_user)
def accept(): if request.method == "POST": instagram_username = session["username"]["username"] bot_obj = client.get(instagram_username)["bot_obj"] no_to_accept = request.form.get("customUserInputNumber", 0) init_dict_items = { Constant.CONSTANT().TOTAL_REQUEST_TO_BE_ACCEPT: no_to_accept, Constant.CONSTANT().IS_REQUEST_COMPLETE: False, Constant.CONSTANT().SUCCESSFUL_ACCEPTED: 0, Constant.CONSTANT().REQUEST_FAILED: 0, } dict_get_index = instagram_username.lower() + Constant.CONSTANT( ).ALL_INFO client.set(dict_get_index, init_dict_items) new_user_count_req = Counter(insta_username=instagram_username, input_request_count=no_to_accept, total_accepted_request=0, total_failed_request=0) new_user_count_req.save() counter_id = new_user_count_req.id session["current_counter_id"] = counter_id session.modified = True ctr_item = Counter.get_one_counter(session["current_counter_id"]) resp = bot_obj.approve_pending_follow_requests( number_of_requests=int(no_to_accept), ctr_item=ctr_item, init_dict_items=init_dict_items, dict_get_index=dict_get_index, counter_ctr=0) if resp == "No request to accept": return "No request to accept" if resp == None: return "True" return "True" elif request.method == "GET": instagram_username = session.get("username").get("username") user_obj = Users.query.filter_by( insta_username=instagram_username).first() last_day = str(days_between(user_obj.till_date)) + " days" return render_template("AcceptRequests.html", last_day=last_day)
def login(self, **args): if self.proxy: args["proxy"] = self.proxy result = self.api.login(**args) import sys sys.path.append("../../") from flask import session from project.users.memcache_ctrl import client if session["username"]["singleton"]: cl_obj = {} cl_obj["api"] = self.api client.set(args["username"], cl_obj) session["username"]["singleton"] = False session.modified = True if result != True: return result return True
def approve_pending_follow_requests(self, number_of_requests, ctr_item, init_dict_items, dict_get_index, counter_ctr): pending = self.get_pending_follow_requests() if number_of_requests < 200: if number_of_requests > len(pending): number_of_requests = len(pending) if pending == []: return "No request to accept" import sys sys.path.append("../../") from flask import session from project.users.memcache_ctrl import client api = client.get(session["username"]["username"])["api"] index = 0 res = [] main_list = [None] * number_of_requests if pending: if number_of_requests <= len(pending): for u in tqdm(pending, desc="Approving users"): if number_of_requests <= 0: break user_id = u["pk"] thread = threading.Thread(target=api.approve_pending_friendship, args=(user_id, main_list, index)) thread.start() res.append(thread) time.sleep(0.01) number_of_requests -= 1 index += 1 for i in res: i.join() for j in main_list: if j: counter_ctr += 1 ctr_item.update_follow_counter(counter_ctr, len(pending)-counter_ctr) init_dict_items[Constant.CONSTANT().TOTAL_REQUEST_TO_BE_ACCEPT] = number_of_requests init_dict_items[Constant.CONSTANT().SUCCESSFUL_ACCEPTED] = counter_ctr init_dict_items[Constant.CONSTANT().REQUEST_FAILED] = len(pending) - counter_ctr init_dict_items[Constant.CONSTANT().IS_REQUEST_COMPLETE] = False if number_of_requests == 0: init_dict_items[Constant.CONSTANT().IS_REQUEST_COMPLETE] = True client.set(dict_get_index, init_dict_items) farhaan = 0 for i in main_list: if i: farhaan += 1 if farhaan > 200: time.sleep(4) elif 100 <= farhaan <= 150: time.sleep(2) elif 50 <= farhaan <= 100: time.sleep(1) if number_of_requests > len(pending): for u in tqdm(pending, desc="Approving users"): if number_of_requests <= 0: break user_id = u["pk"] thread = threading.Thread(target=api.approve_pending_friendship, args=(user_id, main_list, index)) thread.start() res.append(thread) number_of_requests -= 1 time.sleep(0.01) index += 1 for i in res: i.join() for j in main_list: if j: counter_ctr += 1 ctr_item.update_follow_counter(counter_ctr, len(pending) - counter_ctr) init_dict_items[Constant.CONSTANT().TOTAL_REQUEST_TO_BE_ACCEPT] = number_of_requests init_dict_items[Constant.CONSTANT().SUCCESSFUL_ACCEPTED] = counter_ctr init_dict_items[Constant.CONSTANT().REQUEST_FAILED] = len(pending) - counter_ctr init_dict_items[Constant.CONSTANT().IS_REQUEST_COMPLETE] = False if number_of_requests == 0: init_dict_items[Constant.CONSTANT().IS_REQUEST_COMPLETE] = True client.set(dict_get_index, init_dict_items) farhaan = 0 for i in main_list: if i: farhaan += 1 if farhaan > 200: time.sleep(4) elif 100 <= farhaan <= 150: time.sleep(2) elif 50 <= farhaan <= 100: time.sleep(1) approve_pending_follow_requests(self, number_of_requests, ctr_item, init_dict_items, dict_get_index, counter_ctr)