本文整理汇总了Python中telegram.Bot.getFile方法的典型用法代码示例。如果您正苦于以下问题:Python Bot.getFile方法的具体用法?Python Bot.getFile怎么用?Python Bot.getFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类telegram.Bot
的用法示例。
在下文中一共展示了Bot.getFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Core
# 需要导入模块: from telegram import Bot [as 别名]
# 或者: from telegram.Bot import getFile [as 别名]
#.........这里部分代码省略.........
"""Adds a torrent with the given options.
metainfo could either be base64 torrent
data or a magnet link. Available options
are listed in deluge.core.torrent.TorrentOptions.
"""
if self.opts is None:
self.opts = {}
if is_magnet(metainfo):
log.debug(prelog() + 'Adding torrent from magnet ' +
'URI `%s` using options `%s` ...',
metainfo, self.opts)
tid = self.core.add_torrent_magnet(metainfo, self.opts)
self.apply_label(tid)
else:
update.message.reply_text(STRINGS['not_magnet'],
reply_markup=ReplyKeyboardRemove())
except Exception as e:
log.error(prelog() + str(e) + '\n' + traceback.format_exc())
return ConversationHandler.END
except Exception as e:
log.error(prelog() + str(e) + '\n' + traceback.format_exc())
def add_torrent(self, bot, update):
if str(update.message.chat.id) in self.whitelist:
try:
user = update.message.chat.id
log.debug("addtorrent of %s: %s" %
(str(user), update.message.document))
if update.message.document.mime_type == 'application/x-bittorrent':
# Get file info
file_info = self.bot.getFile(update.message.document.file_id)
# Download file
request = urllib2.Request(file_info.file_path, headers=HEADERS)
status_code = urllib2.urlopen(request).getcode()
if status_code == 200:
file_contents = urllib2.urlopen(request).read()
# Base64 encode file data
metainfo = b64encode(file_contents)
if self.opts is None:
self.opts = {}
log.info(prelog() + 'Adding torrent from base64 string' +
'using options `%s` ...', self.opts)
tid = self.core.add_torrent_file(None, metainfo, self.opts)
self.apply_label(tid)
else:
update.message.reply_text(STRINGS['download_fail'],
reply_markup=ReplyKeyboardRemove())
else:
update.message.reply_text(STRINGS['not_file'],
reply_markup=ReplyKeyboardRemove())
return ConversationHandler.END
except Exception as e:
log.error(prelog() + str(e) + '\n' + traceback.format_exc())
def add_url(self, bot, update):
if str(update.message.chat.id) in self.whitelist:
try:
user = update.message.chat.id
log.debug("addurl of %s: %s" % (str(user), update.message.text))
if is_url(update.message.text):