Skip to content

Commit

Permalink
Issue #10: Update docs and validation: mobile phone is required
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekmo committed Jan 6, 2019
1 parent bb40241 commit 472d668
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions telegram_upload/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import getpass
import json
import re
from distutils.version import StrictVersion

import click
Expand All @@ -14,11 +16,28 @@
CAPTION_MAX_LENGTH = 200


def phone_match(value):
match = re.match(r'\+?[0-9.()\[\] \-]+', value)
if match is None:
raise ValueError('{} is not a valid phone'.format(value))
return value


class Client(TelegramClient):
def __init__(self, config_file, **kwargs):
config = json.load(open(config_file))
super().__init__(config.get('session', 'telegram-upload'), config['api_id'], config['api_hash'], **kwargs)

def start(
self,
phone=lambda: click.prompt('Please enter your phone', type=phone_match),
password=lambda: getpass.getpass('Please enter your password: '),
*,
bot_token=None, force_sms=False, code_callback=None,
first_name='New User', last_name='', max_attempts=3):
return super().start(phone=phone, password=password, bot_token=bot_token, force_sms=force_sms,
first_name=first_name, last_name=last_name, max_attempts=max_attempts)

def send_files(self, entity, files, delete_on_success=False):
for file in files:
bar = click.progressbar(label='Uploading {}'.format(os.path.basename(file)),
Expand Down

0 comments on commit 472d668

Please sign in to comment.