【用Python根据用户名和手机号码生成Hash值并创建.cs .h和xlsx文件】

用Python根据用户名和手机号码生成Hash值并创建C Sharp .cs、嵌入式.h和xlsx表格文件

用Python根据用户名和手机号码生成Hash值并创建C Sharp .cs、嵌入式.h和xlsx表格文件,主要是为每个用户创建一个pubkey,并输出C Sharp C#和嵌入式 Keil的工程文件 pubkey.cs和pubkey.h文件。并把用户名和手机号码记录在excel表格中。

python 复制代码
def writeinpara():
    global username
    global email
    username=input('请输入用户名:')
    email=input('请输入手机号码:')
    print("username="+username+"; Email="+email)
#生成md5 hashh
def md5_hash(data: str) -> str:
    m = hashlib.md5()
    m.update(data.encode('utf-8'))
    return m.hexdigest()

下面建立目录

python 复制代码
def createDir(dirpath,username,email):
    global url
    url=dirpath+username+"_"+email
    if(os.path.exists(dirpath+username+"_"+email)):
        shutil.rmtree(url)  #删除目录,包括目录下的所有文件
    os.mkdir(url,0o777)

下面写入CS文件

python 复制代码
    print("writeCSfile =",filepath)
    if os.path.isfile(filepath):
        os.remove(filepath)
    #encoding='utf-8-sig'    
    #with open(filepath, "w", encoding="utf-8") as file:
    with open(filepath, "w", encoding='utf-8-sig') as file:
        file.write(csFileStrBegin+hexdigest+csFileStrEnd)
        file.close()
    #if os.path.isfile(filepath):
    #    print("CS file exist,open it!")
    #    with open(filepath, "w", encoding="utf-8") as file:
    #    file.write(csFileStrBegin+hexdigest+csFileStrEnd)
        #worksheet = workbook.active
    #else:
        #文件不存在,创建新的Exce1文件
    #    print("CS file created!")

写入.h文件

python 复制代码
def writeHfile(filepath,username,email,hexdigest):
    lengthint=len(hexdigest)
    lengthstr=str(lengthint)
    print("writeHfile =",filepath)
    if os.path.isfile(filepath):
        os.remove(filepath)
    with open(filepath, "w", encoding="utf-8") as file:
        file.write("#define USER_PUBKEY_LEN   "+lengthstr+"\r")
        file.write("#define USER_PUBKEY   \""+hexdigest+"\"\r")
        file.close()

写入excel文件

python 复制代码
def writepubkey(workbook,username,email,hexdigest):
    #sheet = workbook.get_sheet_by_name('sheet1')
    sheet = workbook.active
    #last_row = sheet.max_row + 1
    # 获取当前日期和时间
    now = datetime.datetime.now()

    # 格式化日期和时间
    datevalue = now.strftime("%Y-%m-%d")
    timevalue = now.strftime("%H:%M:%S")
    insertData = [datevalue,timevalue, username,email,hexdigest]
    sheet.append(insertData)
    #sheet.cell(last_row+1,  column=1,value=datevalue)
    #sheet.cell(last_row+1,  column=2,value=timevalue)
    #sheet.cell(last_row+1,  column=3,value=username)
    #sheet.cell(last_row+1,  column=4,value=email)
    #sheet.cell(last_row+1,  column=5,value=hexdigest)
    # 保存Excel文件
    workbook.save(filepath)
    workbook.close()

  

视频:B站 柔贝特三哥

一个脚本工具调用Python生产pubkey和嵌入式.h文件和.cs的c#文件,调用keil和visual studio编译arm和c#的工程,执行文件拷贝功能

相关推荐
yue0081 分钟前
C# XML文件的读写V2.0
xml·开发语言·c#
SweetCode3 分钟前
C++ 实现大数加法
开发语言·c++·算法
Nan_Shu_6147 分钟前
学习:JavaScript(5)
开发语言·javascript·学习
像风一样自由202017 分钟前
Rust与Python完全指南:从零开始理解两门语言的区别与关系
开发语言·python·rust
睡前要喝豆奶粉20 分钟前
.NET Core Web API开发需引入的三个基本依赖配置说明
oracle·c#·.netcore
stay_alive.28 分钟前
C++ 四种类型转换
开发语言·c++
房开民1 小时前
RKNN-Toolkit2入门
python
喜欢吃燃面1 小时前
C++:哈希表
开发语言·c++·学习
mit6.8241 小时前
[C++] 时间处理库函数 | `tm`、`mktime` 和 `localtime`
开发语言·c++