Style enhancements for PR #173

This commit is contained in:
Lonami Exo 2017-07-23 17:08:04 +02:00
parent c9e566342e
commit fe2e9f335b

View File

@ -546,10 +546,13 @@ class TelegramClient(TelegramBareClient):
add_extension=True, add_extension=True,
progress_callback=None): progress_callback=None):
"""Downloads the given MessageMedia (Photo, Document or Contact) """Downloads the given MessageMedia (Photo, Document or Contact)
into the desired file(a stream or str), optionally finding its extension automatically into the desired file (a stream or str), optionally finding its
The progress_callback should be a callback function which takes two parameters, extension automatically.
uploaded size (in bytes) and total file size (in bytes).
This will be called every time a part is downloaded""" The progress_callback should be a callback function which takes
two parameters, uploaded size and total file size (both in bytes).
This will be called every time a part is downloaded
"""
if type(message_media) == MessageMediaPhoto: if type(message_media) == MessageMediaPhoto:
return self.download_photo(message_media, file, add_extension, return self.download_photo(message_media, file, add_extension,
progress_callback) progress_callback)
@ -654,26 +657,24 @@ class TelegramClient(TelegramBareClient):
# Ensure that we'll be able to download the contact # Ensure that we'll be able to download the contact
utils.ensure_parent_dir_exists(file) utils.ensure_parent_dir_exists(file)
f = open(file, 'w', encoding='utf-8')
with open(file, 'w', encoding='utf-8') as f:
f.write('BEGIN:VCARD\n')
f.write('VERSION:4.0\n')
f.write('N:{};{};;;\n'.format(first_name, last_name
if last_name else ''))
f.write('FN:{}\n'.format(' '.join((first_name, last_name))))
f.write('TEL;TYPE=cell;VALUE=uri:tel:+{}\n'.format(
phone_number))
f.write('END:VCARD\n')
else: else:
file.write('BEGIN:VCARD\n') f = file
file.write('VERSION:4.0\n')
file.write('N:{};{};;;\n'.format(first_name, last_name try:
if last_name else '')) f.write('BEGIN:VCARD\n')
file.write('FN:{}\n'.format(' '.join((first_name, last_name)))) f.write('VERSION:4.0\n')
file.write('TEL;TYPE=cell;VALUE=uri:tel:+{}\n'.format( f.write('N:{};{};;;\n'.format(
first_name, last_name if last_name else '')
)
f.write('FN:{}\n'.format(' '.join((first_name, last_name))))
f.write('TEL;TYPE=cell;VALUE=uri:tel:+{}\n'.format(
phone_number)) phone_number))
file.write('END:VCARD\n') f.write('END:VCARD\n')
finally:
# Only close the stream if we opened it
if isinstance(file, str):
f.close()
return file return file