Я пытаюсь отредактировать zip-файл, а затем отправить его боту Telegram. Но есть проблема: обычно после того, как сценарий завершен, задание 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))