Skip to content

功能实现:将两个微信小程序的编译结果做融合,并支持后续独立升级迭代

功能列表

  • 上传mp-weixin.zip
  • 解压到指定目录
  • 代码合并并压缩为zip包
  • 支持下载整合包

image-20250409223521823

上传mp-weixin.zip文件后

image-20250409223556401

app.py

python
import streamlit as st
import os
import merge_digitaltown_digitalcard # 业务逻辑
import utils
import shutil

import time
def get_ts():
    now = int(time.time())
    timeArray = time.localtime(now)
    ts = time.strftime("%Y%m%d%H%M%S", timeArray)
    return ts

st.title("整合小镇和名片小程序")

dst_path = "./digitalCardV2_xiaozhen_dev"


uploaded_file = st.file_uploader("上传小程序mp-weixin.zip", type="zip")
if uploaded_file is not None:
    save_path = "uploaded_files"  # 保存文件的目录
    if not os.path.exists(save_path):
        os.makedirs(save_path)
    print("上传成功")
      # 构造保存的文件路径
    zipname = get_ts()+"-"+uploaded_file.name
    file_path = os.path.join(save_path,zipname)

    # 将文件内容写入本地
    with open(file_path, "wb") as f:
        f.write(uploaded_file.getbuffer())
    st.write(f"文件上传成功,处理中...")
    # 解压zip
    extract_path = os.path.join(save_path,zipname.split(".")[0])
    utils.unzip(file_path,extract_path)
    if os.path.exists(dst_path):
        shutil.rmtree(dst_path)
    merge_digitaltown_digitalcard.merge(os.path.join(extract_path,'mp-weixin'),
                                        './shuzixiaozhen',  # 小镇项目
          dst_path)
    st.write(f"整合完成!下载后用微信开发者工具打开,点击上传即可...")
    shutil.rmtree(extract_path)
    download_path = "download_files"
    if not os.path.exists(download_path):
        os.makedirs(download_path)
    download_file = os.path.join(download_path,os.path.basename(file_path))
    utils.zip_folder(dst_path,download_file)
    # 下载压缩包
    with open(download_file, 'rb') as f:
        st.download_button(
            label="下载整合包",
            data=f,
            file_name="shuzixiaozhenV2.zip",
            mime='application/zip'
        )

运行代码

shell
streamlit run app.py