【用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#的工程,执行文件拷贝功能

相关推荐
弹简特3 分钟前
【Java SE】Arrays工具类
java·开发语言
Touper.3 分钟前
JavaSE -- Lambda表达式
java·开发语言
陈敬雷-充电了么-CEO兼CTO7 分钟前
主流大模型Agent框架 AutoGPT详解
人工智能·python·gpt·ai·chatgpt·nlp·aigc
向宇it14 分钟前
Unity Universal Render Pipeline/Lit光照材质介绍
游戏·unity·c#·游戏引擎·材质
KENYCHEN奉孝16 分钟前
Flask3.1打造极简CMS系统
后端·python·flask
秋说17 分钟前
【PTA数据结构 | C语言版】计算1~n与1~m每一项相互乘积的和
c语言·数据结构·算法
秋说21 分钟前
【PTA数据结构 | C语言版】计算1~n平方的和加上1~n的和
c语言·数据结构·算法
C++ 老炮儿的技术栈23 分钟前
Visual Studio 2022 MFC Dialog 添加Toolbar及Tips提示
服务器·c语言·数据库·c++·ide·算法·visual studio
做一个坚强的女汉子25 分钟前
QT保存日志到文件中以及捕捉崩溃日志
开发语言·qt
顾苏洋199025 分钟前
qt绘制饼状图并实现点击即放大点击部分
开发语言·qt