bp.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:bpastebot 作者: mostafaasadi 项目源码 文件源码
def filef(bot,update):
    # get file id
    file = bot.getFile(update.message.document.file_id)
    # create a randon temp file name
    tf = tempfile.mkstemp()
    # download file
    file.download(tf[1])
    # read file content
    try:
        tfco = open(tf[1],"r")
        tfc = tfco.read()
        tfco.close()
    except Exception as e:
        # if it is not text file
        bot.sendMessage(chat_id=update.message.chat_id,reply_to_message_id=update.message.message_id,text=" ?? Please send me a text file")

    # get user name for author
    try:
        author = update.message.from_user.first_name + " " + update.message.from_user.last_name
    except Exception:
        author = "Anonymous user"
    # call paste function
    url = paste(tfc , author)
    # replay the url to user
    bot.sendMessage(chat_id=update.message.chat_id,reply_to_message_id=update.message.message_id,text=url)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号