1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
import os import re from datetime import datetime import requests import random
def search(search_path, search_result, search_fileType_list): all_file = os.listdir(search_path) for each_file in all_file: if os.path.isdir(search_path + each_file): search(search_path + each_file + '/', search_result, search_fileType_list) else: for i in search_fileType_list: if re.findall(f'.*\\{i}$', each_file) == [each_file]: search_result.append(search_path + each_file)
def replace(replace_file_name, replace_old_str, replace_new_str): with open(replace_file_name, "r", encoding = "UTF-8") as f1: content = f1.read() f1.close() t = content.replace(replace_old_str, replace_new_str) with open(replace_file_name, "w", encoding = "UTF-8") as f2: f2.write(t) f2.close()
npm_num_mapping = { '0': ['a', 'b', 'u'], '1': ['c', 'd', 'v'], '2': ['e', 'f', 'w'], '3': ['g', 'h', 'x'], '4': ['i', 'j', 'y'], '5': ['k', 'l', 'z'], '6': ['m', 'n'], '7': ['o', 'p'], '8': ['q', 'r'], '9': ['s', 't'] }
npm_now = datetime.now()
npm_formatted_time = npm_now.strftime("%y%m%d%H%M")
npm_converted_time = '' for char in npm_formatted_time: if char.isdigit(): npm_converted_time += ''.join(random.choice(npm_num_mapping[char]) if char in npm_num_mapping else char) else: npm_converted_time += char
result_npmPackageJson = ['./public/package.json'] old_npmPackageJson_version = '0.0.0' new_npmPackageJson_version = f'0.0.0-{npm_converted_time}' count = 0
for file_name in result_npmPackageJson: replace(file_name, old_npmPackageJson_version, new_npmPackageJson_version) count += 1 print("{} done {}".format(file_name, count))
|