python编写微信小程序命令行操作脚本

本次目的是利用python编写一个脚本,可以通过命令行向指定appid上传微信小程序

import argparse
import json
import os
import hashlib

parser = argparse.ArgumentParser()
parser.add_argument("--appid", help="display a square of a given number", type=str)
parser.add_argument("-u", help="display a square of a given number", type=str)
args = parser.parse_args()

str = args.appid
hl = hashlib.md5()
hl.update(str.encode(encoding='utf-8'))


with open('/Users/edz/WeChatProjects/miniprogram-11/project.config.json', 'r')as f:
    json_data = json.load(f)
    json_data['appid'] = args.appid
with open('/Users/edz/WeChatProjects/miniprogram-11/project.config.json', 'w') as f:
    json.dump(json_data, f, indent=1)

with open('/Users/edz/WeChatProjects/miniprogram-11/utils/appid.js', 'w')as e:
  e.write('const appid = \'' +  hl.hexdigest() + '\'')
  e.write('\nmodule.exports.appid = appid')

os.system('/Applications/wechatwebdevtools.app/Contents/MacOS/cli -u '+args.u)

你可能感兴趣的:(python编写微信小程序命令行操作脚本)