1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #!/usr/bin/python3
- # -*- coding:utf-8 -*-
- # __author__ = '__spring__'
- '''
- 归因上报抖音数据的脚本
- '''
- import json
- import os
- class Handle:
- def __init__(self):
- pass
-
- """
- 将替换的字符串写到一个新的文件中,然后将原文件删除,新文件改为原来文件的名字
- :param file: 文件路径
- :param old_str: 需要替换的字符串
- :param new_str: 替换的字符串
- :return: None
- """
- def updateFile(self,file,old_str,new_str):
- with open(file, "r", encoding="utf-8") as f1,open("%s.bak" % file, "w", encoding="utf-8") as f2:
- for line in f1:
- if old_str in line:
- line = line.replace(old_str, new_str)
- f2.write(line)
- os.remove(file)
- os.rename("%s.bak" % file, file)
-
- def main(self):
- # 读取需要打包的app 列表
- with open('./app_list.json','r') as f :
- data = f.read()
- data = json.loads(data)
- app_list = data["app_list"]
- tar_ver = data["taroConfig"]
-
- #读取版本号
- with open('./package.json','r') as f :
- package = f.read()
- package = json.loads(package)
-
- #更新版本号
- with open('./package.json','w') as f :
- package["taroConfig"] = tar_ver
- json.dump(package,f,indent=4,ensure_ascii=False)
-
-
- #遍历需要打包的应用
- for app_info in app_list:
- path_name = app_info["path_name"]
- #读取配置文件
- with open(path_name,'r') as f:
- pro_data = f.read()
- pro_data = json.loads(pro_data)
- #修改配置文件
- with open(path_name,'w') as f:
- pro_data["appid"] = app_info["appid"]
- pro_data["projectname"] = app_info["projectname"]
- pro_data["description"] = app_info["description"]
- json.dump(pro_data,f,indent=4,ensure_ascii=False)
-
- #修改抖音自定义导航栏的样式
- # self.updateFile("./src/pages/albums_play/index.config.js","custom","default")
- if app_info["appid"].find("wx") > -1:
- #修改打包插件的appid
- self.updateFile("./config/index.js","__APPID__",app_info["appid"])
- #修改抖音自定义导航栏的样式
- # self.updateFile("./src/pages/albums_play/index.config.js","default","custom")
-
- #自己添加打包插件
- self.updateFile("./config/index.js","plugins:[]",'plugins:[["@tarojs/plugin-mini-ci", CIPluginOpt]]')
-
- #开始运行打包命令
- cmd = "npm run build:weapp_upload"
- if path_name.find("tt") > 0:
- cmd = "npm run build:tt_upload"
- os.system(cmd) #执行命令
-
- if app_info["appid"].find("wx") > -1:
- #修改打包插件的appid
- self.updateFile("./config/index.js",app_info["appid"],"__APPID__")
-
- self.updateFile("./config/index.js",'plugins:[["@tarojs/plugin-mini-ci", CIPluginOpt]]',"plugins:[]")
-
- pass
- if __name__=='__main__':
- Handle().main()
|