(self, target)
| 13929 | return min(100, score) |
| 13930 | |
| 13931 | async def analyze_phone(self, target): |
| 13932 | info = {"00. Input": target} |
| 13933 | clean_target = re.sub(r"[^0-9+]", "", target or "") |
| 13934 | wa_link, tg_link = f"https://wa.me/{clean_target.lstrip('+')}", f"https://t.me/{clean_target.lstrip('+')}" |
| 13935 | main_img = "https://cdn-icons-png.flaticon.com/512/159/159832.png" |
| 13936 | |
| 13937 | if not phonenumbers_available: |
| 13938 | info["Parsing"] = "Errore: phonenumbers non disponibile. Usa solo formati riconoscibili." |
| 13939 | info["20. WhatsApp"] = f"Vedi link: {wa_link}" |
| 13940 | info["21. Telegram"] = "Non disponibile" |
| 13941 | return main_img, info, tg_link, wa_link |
| 13942 | |
| 13943 | try: |
| 13944 | pn = phonenumbers.parse(target) |
| 13945 | tz_list = phone_timezone.time_zones_for_number(pn) or [] |
| 13946 | carrier_name = (carrier.name_for_number(pn, "en") or "").strip() |
| 13947 | country_code = region_code_for_country_code(pn.country_code) |
| 13948 | geo_desc = geocoder.description_for_number(pn, "en") or "" |
| 13949 | |
| 13950 | info["01. Formato Input"] = phonenumbers.format_number(pn, phonenumbers.PhoneNumberFormat.INTERNATIONAL) |
| 13951 | info["02. Input Normalizzato"] = phonenumbers.format_number(pn, phonenumbers.PhoneNumberFormat.E164) |
| 13952 | info["03. Formato E164 (solo cifre)"] = info["02. Input Normalizzato"].replace("+", "") |
| 13953 | info["04. Formato Nazionale"] = phonenumbers.format_number(pn, phonenumbers.PhoneNumberFormat.NATIONAL) |
| 13954 | info["05. Validation"] = "Possibile" if phonenumbers.is_possible_number(pn) else "Possibile ma insolito" |
| 13955 | if phonenumbers.is_valid_number(pn): |
| 13956 | info["05. Validità"] = "Valido" |
| 13957 | else: |
| 13958 | info["05. Validità"] = "Non valido" |
| 13959 | info["06. Prefisso internazionale"] = f"+{pn.country_code}" |
| 13960 | info["07. ISO Paese"] = country_code or "N/D" |
| 13961 | info["08. Paese"] = geo_desc or self._phone_country_name(country_code) |
| 13962 | info["09. Paese ISO nome"] = self._phone_country_name(country_code) if country_code else "N/D" |
| 13963 | if geo_desc and "," in geo_desc: |
| 13964 | parts = [x.strip() for x in geo_desc.split(",") if x.strip()] |
| 13965 | if len(parts) > 1: |
| 13966 | info["16. Regione stimata"] = parts[-1] |
| 13967 | info["17. Città stimata"] = parts[0] |
| 13968 | else: |
| 13969 | info["16. Regione stimata"] = geo_desc |
| 13970 | info["10. Timezone"] = ", ".join(sorted(set(tz_list))) if tz_list else "N/D" |
| 13971 | info["Timezone"] = info["10. Timezone"] |
| 13972 | info["11. Carrier"] = carrier_name or "N/D" |
| 13973 | info["Carrier"] = info["11. Carrier"] |
| 13974 | info["12. Operatore normalizzato"] = self._normalize_carrier_name(carrier_name) if carrier_name else "N/D" |
| 13975 | info["Carrier normalizzato"] = info["12. Operatore normalizzato"] |
| 13976 | info["13. Numero Type"] = str(phonenumbers.number_type(pn)) |
| 13977 | ntype = str(phonenumbers.number_type(pn)).lower() |
| 13978 | info["14. Tipo Linea"] = "Mobile" if "mobile" in ntype else "Voce/Fisso" |
| 13979 | info["Tipo numero"] = info["14. Tipo Linea"] |
| 13980 | |
| 13981 | normalized = re.sub(r"\D", "", info["02. Input Normalizzato"]) |
| 13982 | original_digits = re.sub(r"\D", "", target or "") |
| 13983 | info["15. Coerenza formato"] = "OK" if normalized == original_digits else "Corretto con normalizzazione" |
| 13984 | |
| 13985 | if phonenumbers.is_valid_number(pn): |
| 13986 | ext = self._phone_portability_hint(str(pn.country_code), str(pn.national_number)) |
| 13987 | if isinstance(ext, dict): |
| 13988 | info.update(ext) |
no test coverage detected