mirror of
				https://github.com/LonamiWebs/Telethon.git
				synced 2025-11-04 09:57:29 +03:00 
			
		
		
		
	Style enhancements for PR #173
This commit is contained in:
		
							parent
							
								
									c9e566342e
								
							
						
					
					
						commit
						fe2e9f335b
					
				| 
						 | 
					@ -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')
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            f = file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            with open(file, 'w', encoding='utf-8') as f:
 | 
					        try:
 | 
				
			||||||
            f.write('BEGIN:VCARD\n')
 | 
					            f.write('BEGIN:VCARD\n')
 | 
				
			||||||
            f.write('VERSION:4.0\n')
 | 
					            f.write('VERSION:4.0\n')
 | 
				
			||||||
                f.write('N:{};{};;;\n'.format(first_name, last_name
 | 
					            f.write('N:{};{};;;\n'.format(
 | 
				
			||||||
                                                 if last_name else ''))
 | 
					                first_name, last_name if last_name else '')
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
            f.write('FN:{}\n'.format(' '.join((first_name, last_name))))
 | 
					            f.write('FN:{}\n'.format(' '.join((first_name, last_name))))
 | 
				
			||||||
            f.write('TEL;TYPE=cell;VALUE=uri:tel:+{}\n'.format(
 | 
					            f.write('TEL;TYPE=cell;VALUE=uri:tel:+{}\n'.format(
 | 
				
			||||||
                phone_number))
 | 
					                phone_number))
 | 
				
			||||||
            f.write('END:VCARD\n')
 | 
					            f.write('END:VCARD\n')
 | 
				
			||||||
 | 
					        finally:
 | 
				
			||||||
        else:
 | 
					            # Only close the stream if we opened it
 | 
				
			||||||
            file.write('BEGIN:VCARD\n')
 | 
					            if isinstance(file, str):
 | 
				
			||||||
            file.write('VERSION:4.0\n')
 | 
					                f.close()
 | 
				
			||||||
            file.write('N:{};{};;;\n'.format(first_name, last_name
 | 
					 | 
				
			||||||
            if last_name else ''))
 | 
					 | 
				
			||||||
            file.write('FN:{}\n'.format(' '.join((first_name, last_name))))
 | 
					 | 
				
			||||||
            file.write('TEL;TYPE=cell;VALUE=uri:tel:+{}\n'.format(
 | 
					 | 
				
			||||||
                phone_number))
 | 
					 | 
				
			||||||
            file.write('END:VCARD\n')
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return file
 | 
					        return file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user