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

相关推荐
爱吃烤鸡翅的酸菜鱼几秒前
Spring Boot 实现 WebSocket 实时通信:从原理到生产级实战
java·开发语言·spring boot·后端·websocket·spring
雪域迷影5 分钟前
C++中编写UT单元测试用例时如何mock非虚函数?
开发语言·c++·测试用例·gmock·cpp-stub开源项目
AI街潜水的八角1 小时前
Python电脑屏幕&摄像头录制软件(提供源代码)
开发语言·python
hadage2331 小时前
--- git 的一些使用 ---
开发语言·git·python
lly2024063 小时前
HTML与CSS:构建网页的基石
开发语言
一只会写代码的猫3 小时前
面向高性能计算与网络服务的C++微内核架构设计与多线程优化实践探索与经验分享
java·开发语言·jvm
是小胡嘛5 小时前
C++之Any类的模拟实现
linux·开发语言·c++
口袋物联5 小时前
设计模式之工厂模式在 C 语言中的应用(含 Linux 内核实例)
linux·c语言·设计模式·简单工厂模式
csbysj20206 小时前
Vue.js 混入:深入理解与最佳实践
开发语言