Python,Heroku不会还原对文件所做的编辑

时间:2018-09-02 18:32:00

标签: python heroku zipfile

我正在尝试编辑一个zip文件,然后将其发送到电报机器人。但是有一个问题:通常在完成脚本后,heroku会删除对文件所做的任何更改(如果有任何更改)。但是由于某种原因,它暂时无法执行此操作,每次我将其附加到zip文件时,都会不断地重复添加相同的文件。我想我的代码有些混乱,因为在一切正常之前,..有什么想法吗?

import os
import re
import time
from datetime import datetime
from typing import List
from zipfile import ZipFile

from telegram import ChatAction
from telegram.ext import Filters, MessageHandler

from bot import dispatcher, update


def update_binary(ver):
    with open("update-binary.txt", "r+") as f:
        content = f.read()
        f.seek(0, 0)
        get_date = datetime.today().strftime('%d-%m-%Y')
        replace_placeholder = re.sub(
            "placeholder", 'get_ver="{}"\nget_date="{}"'.format(ver, get_date), content)
        f.write(replace_placeholder)


def add_to_zip():
    with ZipFile("MinAurora-signed.zip", "a") as aurora_zip:
        aurora_zip.write(
            "update-binary.txt", "/META-INF/com/google/android/update-binary")
        aurora_zip.write("aurora_build.apk",
                         "/system/priv-app/AuroraStore/AuroraStore.apk")
        aurora_zip.close()


def build(bot, update):
    message = update.effective_message
    doc = message.document
#    aurora_zip = open("MinAurora-signed.zip", "rb")
    if doc.file_name.startswith('Aurora') and doc.file_name.endswith('.apk'):
        split = re.split(r'-|.apk', doc.file_name)
        version = '-'.join(split[-2:])
        bot.send_chat_action(chat_id=update.message.chat_id,
                             action=ChatAction.UPLOAD_DOCUMENT)
        apk_id = doc.file_id
        get_apk = bot.get_file(apk_id)
        get_apk.download('aurora_build.apk')
        update_binary(version)
        add_to_zip()
        document = open("MinAurora-signed.zip", "rb")
        bot.send_document(chat_id=update.message.chat_id,
                          document=document)
        document.close()


dispatcher.add_handler(MessageHandler(Filters.document, build))
   import os
    import re
    import time
    from datetime import datetime
    from typing import List
    from zipfile import ZipFile

    from telegram import ChatAction
    from telegram.ext import Filters, MessageHandler

    from bot import dispatcher, update


    def update_binary(ver):
        with open("update-binary.txt", "r+") as f:
            content = f.read()
            f.seek(0, 0)
            get_date = datetime.today().strftime('%d-%m-%Y')
            replace_placeholder = re.sub(
                "placeholder", 'get_ver="{}"\nget_date="{}"'.format(ver, get_date), content)
            f.write(replace_placeholder)


    def add_to_zip():
        with ZipFile("MinAurora-signed.zip", "a") as aurora_zip:
            aurora_zip.write(
                "update-binary.txt", "/META-INF/com/google/android/update-binary")
            aurora_zip.write("aurora_build.apk",
                             "/system/priv-app/AuroraStore/AuroraStore.apk")
            aurora_zip.close()


    def build(bot, update):
        message = update.effective_message
        doc = message.document
    #    aurora_zip = open("MinAurora-signed.zip", "rb")
        if doc.file_name.startswith('Aurora') and doc.file_name.endswith('.apk'):
            split = re.split(r'-|.apk', doc.file_name)
            version = '-'.join(split[-2:])
            bot.send_chat_action(chat_id=update.message.chat_id,
                                 action=ChatAction.UPLOAD_DOCUMENT)
            apk_id = doc.file_id
            get_apk = bot.get_file(apk_id)
            get_apk.download('aurora_build.apk')
            update_binary(version)
            add_to_zip()
            document = open("MinAurora-signed.zip", "rb")
            bot.send_document(chat_id=update.message.chat_id,
                              document=document)
            document.close()


    dispatcher.add_handler(MessageHandler(Filters.document, build))

0 个答案:

没有答案