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

相关推荐
流星白龙1 小时前
【Qt】1.安装QT
开发语言·qt
励志不掉头发的内向程序员1 小时前
【Linux系列】解码 Linux 内存地图:从虚拟到物理的寻宝之旅
linux·运维·服务器·开发语言·学习
Happy coder2 小时前
【avalonia教程】11字符串格式化、avalonia自带绑定值的转换
c#·avalonia
深盾科技2 小时前
C/C++逆向分析实战:变量的奥秘与安全防护
c语言·c++·安全
superxxd3 小时前
跨平台音频IO处理库libsoundio实践
开发语言·qt·音视频
_OP_CHEN5 小时前
C++基础:(十二)list类的基础使用
开发语言·数据结构·c++·stl·list类·list核心接口·list底层原理
Bellafu6666 小时前
selenium常用的等待有哪些?
python·selenium·测试工具
小白学大数据6 小时前
Python爬虫常见陷阱:Ajax动态生成内容的URL去重与数据拼接
爬虫·python·ajax
2401_841495647 小时前
【计算机视觉】基于复杂环境下的车牌识别
人工智能·python·算法·计算机视觉·去噪·车牌识别·字符识别
Adorable老犀牛8 小时前
阿里云-ECS实例信息统计并发送统计报告到企业微信
python·阿里云·云计算·企业微信