2 Commits

Author SHA1 Message Date
msramalho
9ed496d690 remove whitespace in phone numbers 2024-01-30 22:37:00 +00:00
msramalho
3c9cb2ab99 click.prompt to input for notebooks compatibility 2024-01-25 17:35:48 +00:00
3 changed files with 9 additions and 10 deletions

View File

@@ -57,7 +57,7 @@ The result will be written to the console but also written as JSON to a `results
For each phone number, you can expect the following possible responses:
1. If available, you will receive the Telegram Username,Name, and ID that are connected with this number.
1. If available, you will receive the Telegram Username, Name, and ID that are connected with this number.
2. 'no username detected'. This means that it looks like the number was used to create a Telegram account but the user did not choose a Telegram Username. It is optional to create a Username on Telegram.
3. 'ERROR: no response, the user does not exist or has blocked contact adding.': There can be several reasons for this response. Either the phone number has not been used to create a Telegram account. Or: The phone number is connected to a Telegram account but the user has restricted the option to find him/her via the phone number.
4. Or: another error occurred.

View File

@@ -1,6 +1,6 @@
[tool.poetry]
name = "telegram-phone-number-checker"
version = "1.0.1"
version = "1.0.3"
description = "Check if phone numbers are connected to Telegram accounts."
authors = ["Bellingcat"]
license = "MIT"

View File

@@ -1,7 +1,6 @@
import os, json
from telethon.sync import TelegramClient, errors
import os, json, re
from telethon.sync import TelegramClient, errors, functions
from telethon.tl.types import InputPhoneContact
from telethon import functions
from dotenv import load_dotenv
from getpass import getpass
import click
@@ -46,9 +45,9 @@ def validate_users(client, phone_numbers):
The function uses the get_api_response function to first check if the user exists and if it does, then it returns the first user name and the last user name.
'''
if not phone_numbers or not len(phone_numbers):
phone_numbers = click.prompt('Enter the phone numbers to check, separated by commas')
phone_numbers = input('Enter the phone numbers to check, separated by commas: ')
result = {}
phones = [p.strip() for p in phone_numbers.split(",")]
phones = [re.sub(r"\s+", "", p, flags=re.UNICODE) for p in phone_numbers.split(",")]
try:
for phone in phones:
if phone not in result:
@@ -62,9 +61,9 @@ def validate_users(client, phone_numbers):
def login(api_id, api_hash, phone_number):
"""Create a telethon session or reuse existing one"""
print('Logging in...', end="", flush=True)
API_ID = api_id or os.getenv('API_ID') or click.prompt('Enter your API ID')
API_HASH = api_hash or os.getenv('API_HASH') or click.prompt('Enter your API HASH')
PHONE_NUMBER = phone_number or os.getenv('PHONE_NUMBER') or click.prompt('Enter your phone number')
API_ID = api_id or os.getenv('API_ID') or input('Enter your API ID: ')
API_HASH = api_hash or os.getenv('API_HASH') or input('Enter your API HASH: ')
PHONE_NUMBER = phone_number or os.getenv('PHONE_NUMBER') or input('Enter your phone number: ')
client = TelegramClient(PHONE_NUMBER, API_ID, API_HASH)
client.connect()
if not client.is_user_authorized():