def run(self, task_id: int, authorization_data: dict) -> dict: """ Run task :param authorization_data: dict :param task_id: int :return: dict """ data = dict() print(self.account_data) # initialize request parameters initialization_parameters = self.initialization_parameters() # initialize request headers initialization_headers = self.initialization_headers() # run pre-requests pre_requests = self.run_pre_requests() # run login data = self.social_api.login(self.account_data, initialization_parameters, initialization_headers) sys_report = SystemApiRequests(self.individual_id) # send report to api sys_report.task_report(task_id, data) return data
def run(self, task_id: int, initialization_parameters: object, initialization_headers: object, initialization_cookies: object) -> dict: """ Run task :param initialization_parameters: object :param initialization_cookies: object :param initialization_headers: object :param task_id: int :return: dict """ sys.stdout.write("Task PageHashTask is running!\n") data_result = self.social_api.page_hash_task(initialization_parameters, initialization_headers, initialization_cookies) if data_result["status"]: if data_result["data"]["status"] == 'ok': try: initialization_parameters.fetch_media_item_cursor = \ data_result["data"]["data"]["user"]["edge_web_feed_timeline"]["page_info"]["end_cursor"] initialization_parameters.has_next_page = \ data_result["data"]["data"]["user"]["edge_web_feed_timeline"]["page_info"]["has_next_page"] # set posts id list initialization_parameters.posts_id_list.clear() for post_id in data_result["data"]["data"]["user"]["edge_web_feed_timeline"]["edges"]: try: initialization_parameters.posts_id_list.append(str(post_id["node"]["id"])) except KeyError: continue sys.stdout.write(f"Task PageHashTask completed work successfully!\n") except KeyError as error: sys.stdout.write( f"The PageHashTask for the bot number {self.individual_id} was not correct.!!!" f" Check the log file loging_fbi.log!\n") error_text = f"Some parameters from response of instagram (graphql/query/) was not correct.!!! Error - {error}" logger.warning(error_text) data_result["status"] = False else: sys.stdout.write( f"The FlippingTapeTask for the bot number {self.individual_id} was not correct.!!!" f" Check the log file loging_fbi.log!\n") error_text = f"Some parameters from response of instagram (graphql/query/) was not correct.!!! Data - {data_result['data']}" logger.warning(error_text) data_result["status"] = False else: sys.stdout.write( f"The PageHashTask for the bot number {self.individual_id} was not correct.!!!" f" Check the log file loging_fbi.log!\n") error_text = f"Some parameters from response of instagram (graphql/query/) was not correct.!!! Data - {data_result['data']}" logger.warning(error_text) # send report to api sys_report = SystemApiRequests(self.individual_id) sys_report.task_report(task_id, data_result) return data_result
def run(self, task_id: int, initialization_parameters: object, initialization_headers: object, initialization_cookies: object) -> dict: """ Run task login :param initialization_cookies: object :param initialization_headers: object :param initialization_parameters: object :param task_id: int :return: dict """ sys.stdout.write("Task Login is running!\n") # run login # these requests are desirable and in addition, # the request will allow you to get the parameter cookie - csrftoken, mid, ig_did... from the api login_data = self.social_api.login(self.account_data, initialization_headers, initialization_cookies) # send report to api sys_report = SystemApiRequests(self.individual_id) sys_report.task_report(task_id, login_data) if not login_data["status"]: sys.stdout.write(f"The authorization process for the bot number {self.individual_id} was not correct.!!!" f" Check the log file loging_fbi.log!\n") return {"status": False} # check if params csrftoken, mid, ig_did are passed if initialization_cookies.check_init_attributes(): sys.stdout.write(f"Task Login completed work successfully!\n") return {"status": True} return {"status": False}
def run(self, task_id: int, authorization_data: dict) -> dict: """ Run task :param authorization_data: dict :param task_id: int :return: dict """ data_result = self.social_api.like({}, authorization_data) sys_report = SystemApiRequests(self.individual_id) # send report to api sys_report.task_report(task_id, data_result) return data_result
def run(self, task_id: int, initialization_parameters: object, initialization_headers: object, initialization_cookies: object) -> dict: """ Run task :param initialization_headers: object :param initialization_cookies: object :param initialization_parameters: object :param task_id: int :return: dict """ sys.stdout.write("Task LikeTask is running!\n") data_result = dict() post_id = initialization_parameters.get_post_id() if post_id: data_result = self.social_api.like(initialization_parameters, initialization_headers, initialization_cookies, post_id) sys_report = SystemApiRequests(self.individual_id) # send report to api sys_report.task_report(task_id, data_result) return data_result
sys.stdout.write("No tasks, I work autonomously!\n") self._perform_task(self.task_objects["flipping_tape"], 3) time.sleep(10) continue def _perform_task(self, task_object, task_id): data_task = task_object.run(task_id, self.authorization_data) time.sleep(10) return data_task def _get_new_task(self) -> dict: new_task = self.system_api.get_new_task() return new_task def _send_data_api(self, data): logger.warning(f"Bot {data} start working!!!") def _set_log_record_api(self): pass if __name__ == "__main__": bot = InstaBot("http://localhost", 3500, InstagramRequestsWeb("http://localhost", 8000), SystemApiRequests(1), 1, { "username": "******", "password": 1234567 }) bot.start()
sys.stdout.write("Server error!!!\n") time.sleep(10) continue else: sys.stdout.write("No tasks, I work autonomously!\n") task_result = self._perform_task(self.task_objects["flipping_tape"], 2) if task_result["status"]: time.sleep(random.randint(25, 60)) continue return None def _perform_task(self, task_object: object, task_id: int) -> dict: data_task = task_object.run(task_id, self.initialization_parameters, self.initialization_headers, self.initialization_cookies) return data_task def _get_new_task(self) -> dict: new_task = self.system_api.get_new_task() return new_task if __name__ == "__main__": bot = InstaBot("http://localhost", 3500, InstagramRequestsWeb(), SystemApiRequests(1), 1, {"username": "******", "password": '******'}, {"st": 1}, login_task=True) bot.start()