Beispiel #1
0
 def _save_file_to_evernote(self, file_id, file_size, message: Message):
     max_size = 20 * 1024 * 1024 # telegram restriction. We can't download any file that has size more than 20Mb
     if file_size > max_size:
         raise EvernoteBotException('File too big. Telegram does not allow to the bot to download files over 20Mb.')
     filename, short_name = download_telegram_file(self.api, file_id, self.config["tmp_root"])
     user_data = self.users.get(message.from_user.id)
     user = BotUser(**user_data)
     self._check_evernote_quota(user, file_size)
     title = message.caption or message.text[:20] or 'File'
     files = ({'path': filename, 'name': short_name},)
     self.save_note(user, text=message.text, title=title, files=files)
 def _save_file_to_evernote(self, file_id, file_size, message: Message):
     max_size = 20 * 1024 * 1024 # telegram restriction. We can't download any file that has size more than 20Mb
     if file_size > max_size:
         raise EvernoteBotException('File too big. Telegram does not allow to the bot to download files over 20Mb.')
     filename, short_name = download_telegram_file(self.api, file_id, self.config["tmp_root"])
     user_data = self.users.get(message.from_user.id)
     user = BotUser(**user_data)
     self._check_evernote_quota(user, file_size)
     title = self.get_caption(message) or (message.text and message.text[:20]) or 'File'
     files = ({'path': filename, 'name': short_name},)
     text = ''
     telegram_link = message.get_telegram_link()
     if telegram_link:
         text = f'<div><p><a href="{telegram_link}">{telegram_link}</a></p><pre>{message.caption}</pre></div>'
     self.save_note(user, '', title=title, files=files, html=text)
Beispiel #3
0
 def save_file_to_evernote(self, file_id, file_size, message: dict):
     # telegram restriction. We can't download file > 20Mb
     max_size = 20 * 1024 * 1024
     if file_size > max_size:
         raise EvernoteBotException(
             'File too big. Telegram does not allow to the bot to download files over 20Mb.'
         )
     filename, short_name = download_telegram_file(self.api, file_id,
                                                   self.config['tmp_root'])
     self._check_evernote_quota(file_size)
     title = get_message_caption(message) or (
         message['text'] and message['text'][:20]) or 'File'
     files = ({'path': filename, 'name': short_name}, )
     text = ''
     telegram_link = get_telegram_link(message)
     if telegram_link:
         text = f'<div><p><a href="{telegram_link}">{telegram_link}</a></p><pre>{message["caption"]}</pre></div>'
     self.save_note('', title=title, files=files, html=text)