def get_any_active(self): tokens = self.get_all_active() if tokens: return tokens[0] Log.error("No valid token detected. Script will crash") return {}
def get_information_by_phone(self, phone): Log.d("Call get_information_by_phone with phone ", phone) result_name = self.get_name_by_phone(phone) result_tags = self.get_tags_by_phone(phone) self.update_config() return dict(**result_name, **result_tags)
def get_tags_by_phone(self, phoneNumber): Log.d("Call get_tags_by_phone with phoneNumber ", phoneNumber) response = self.requester.get_phone_tags(phoneNumber) if response: result = { "tags": [tag["tag"] for tag in response["result"]["tags"]] } return result return {"tags": []}
def repeat_last_task(self): function = self.current_task["function"] phone = self.current_task["phone"] if function == "get_phone_name": return self.get_phone_name(phone) if function == "get_phone_tags": return self.get_phone_tags(phone) Log.error("Incorrect task for repeat") return None
def get_name_by_phone(self, phoneNumber): Log.d("Call get_name_by_phone with phoneNumber ", phoneNumber) response = self.requester.get_phone_name(phoneNumber) if response: name = response["result"]["profile"]["name"] surname = response["result"]["profile"]["surname"] if not name and not surname: user_name = None else: user_name = f"{parse_none(name)} {parse_none(surname)}" country_code = response["result"]["profile"]["countryCode"] country = response["result"]["profile"]["country"] if not country: country_name = f"{parse_none(country_code)}" else: country_name = f"{country} {parse_none(country_code)}" result = { "name": user_name, "phoneNumber": response["result"]["profile"]["phoneNumber"], "country": country_name, "displayName": response["result"]["profile"]["displayName"], "profileImage": response["result"]["profile"]["profileImage"], "email": response["result"]["profile"]["email"], "is_spam": True if response["result"]["spamInfo"]["degree"] == "high" else False, } remain_count = response["result"]["subscriptionInfo"]["usage"][ "search"]["remainingCount"] self.updater.update_remain_count_by_token(config.TOKEN, remain_count) return result else: return { "name": None, "phoneNumber": phoneNumber, "country": config.COUNTRY, "displayName": "Not Found", "profileImage": None, "email": None, "is_spam": False, }
def _print_beauty_output(self, data): Log.d("Call _print_beauty_output with data ", data) print("Phone:", data["phoneNumber"]) print("User:"******"displayName"]) if "tags" in data.keys() and data["tags"]: print("Tag list: ") for tag in data["tags"]: print( "\t", tag.encode("utf-8", errors="replace").decode("utf-8", errors="replace"), )
def get_from_file(self, file): Log.d("Call get_from_file with file ", file) with open(file, "r") as f: phones = f.read().split("\n") for phone in phones: self.print_information_by_phone(phone)
def print_information_by_phone(self, phone): Log.d("Call print_information_by_phone with phone ", phone) data = self.get_information_by_phone(phone) self._print_beauty_output(data)
def get_name_by_phone_with_change_token(self, phone): Log.d("Call get_name_by_phone_with_change_token with phone ", phone) result = self.get_name_by_phone(phone) self.update_config() return result
def _parse_response(self, response): Log.d("Call _parse_response with response:", response.text) if response.status_code == 200: return True, response.json()["data"] if response.status_code == 201: return True, response.json() else: Log.d("Not correct answer from server.") response = response.json() if "data" in response.keys(): response = response["data"] Log.d("Response: ", response) response = json.loads(self.cipher.decrypt_AES_b64(response)) Log.d("Response decrypted: ", response) errorCode = response["meta"]["errorCode"] if errorCode == "403004": print("Captcha is detected. ") from getcontact.decode_captcha import CaptchaDecode c = CaptchaDecode() code, path = c.decode_response(response) self.decode_captcha(code) return False, {"repeat": True} if errorCode == "404001": print("No information about phone in database") if errorCode == "403021": # Token dead Log.d("Token is dead.", config.TOKEN) self.updater.update_remain_count_by_token(config.TOKEN, 0) else: Log.d("Unhandled error with response", response) Log.d("Try to use correct token") return False, {}
def _send_post(self, url, data): Log.d("Call _send_post with url:", url, "data:", data) response = requests.post(url, data=data, headers=self.headers) self.update_timestamp() return self._parse_response(response)