Skip to main content

Mr.Lee's Helpers

Project description

🌺commands

Microsoft SQL Server命令:

  • 创建数据库
pylhb mssql create -S localhost\\sqlexpress -U sa -P fpsoft@123 -D test -mdf D:\\dd\\test.mdf -ldf D:\\dd\\test_log.ldf
  • 附加数据库
pylhb mssql attach -S localhost\\sqlexpress -U sa -P fpsoft@123 -D test -mdf D:\\dd\\test.mdf -ldf D:\\dd\\test_log.ldf
pylhb mssql fujia -S localhost\\sqlexpress -U sa -P fpsoft@123 -D test -mdf D:\\dd\\test.mdf -ldf D:\\dd\\test_log.ldf
  • 分离数据库
pylhb mssql detach -S localhost\\sqlexpress -U sa -P fpsoft@123 -D test
pylhb mssql fenli -S localhost\\sqlexpress -U sa -P fpsoft@123 -D test
  • 备份数据库
pylhb mssql backup -S localhost\\sqlexpress -U sa -P fpsoft@123 -D MyCustomer --file D:\\dd\\bkfile.bak
  • 备份所有数据库
pylhb mssql backupall -S localhost\\sqlexpress -U sa -P fpsoft@123 -D MyCustomer --file D:\\dd\\name.bak
  • 恢复数据库
pylhb mssql restore -S localhost\\sqlexpress -U sa -P fpsoft@123 -D MyCustomer --file D:\\dd\\bkfile.bak
  • 清除日志
pylhb mssql dellog -S localhost\\sqlexpress -U sa -P fpsoft@123 -D MyCustomer
  • 清除null
pylhb mssql clearnull -S localhost\\sqlexpress -U sa -P fpsoft@123 -D MyCustomer
  • 删除数据库
pylhb mssql drop -S localhost\\sqlexpress -U sa -P fpsoft@123 -D test --force
  • 执行SQL文件
pylhb mssql runsql -S localhost\\sqlexpress -U sa -P fpsoft@123 -D MyCustomer --file D:\\dd\\test.sql

IIS命令:

  • 创建应用程序池
pylhb iis createapppool --poolname MyPool
pylhb iis createapppool --poolname MyPool --runtime v4.0 --start32
  • 删除应用程序池
pylhb iis deleteapppool --poolname MyPool
  • 创建网站
pylhb iis createwebsite --sitename MyWebsite --path D:\\dd --port 88 --poolname MyPool
  • 创建网站下的应用
pylhb iis createwebsiteapp --sitename MyWebsite --apppath /webapi --path D:\\dd --poolname MyPool
  • 删除网站
pylhb iis deletewebsite --sitename MyWebsite
  • 删除网站应用
pylhb iis deletewebsiteapp --sitename MyWebsite --apppath /webapi
  • 检查应用程序池是否存在
pylhb iis checkapppool  --poolname MyPool
  • 检查网站是否存在
pylhb iis checkwebsite  --sitename MyWebsite
  • 检查网站下在应用是否存在
pylhb iis checkwebsiteapp  --sitename MyWebsite --apppath /webapi
  • 启动应用程序池
pylhb iis startapppool  --poolname MyPool
  • 停止应用程序池
pylhb iis stopapppool  --poolname MyPool
  • 启动网站
pylhb iis startwebsite  --sitename MyWebsite
  • 停止网站
pylhb iis stopwebsite  --sitename MyWebsite
  • 获取应用程序池状态
pylhb iis getapppoolstate  --poolname MyPool
  • 获取网站状态
pylhb iis getwebsitestate  --sitename MyWebsite
  • 获取应用程序池列表
pylhb iis getapppoollist
  • 获取网站列表
pylhb iis getwebsitelist
  • 备份IIS
pylhb iis backupiis --backupname bk2026
  • 恢复IIS
pylhb iis restoreiis --backupname bk2026

🌺mymssql模块

通过ODBC访问Microsoft SQL Server。

注意:

ODBC Driver 17 for SQL Server下载:
https://learn.microsoft.com/zh-cn/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-ver16
注意,如果是ODBC Driver 18 for SQL Server,那实例化时记得传driver.

使用示例:

from pylhb.mymssql import MyMSSQL

if __name__ == "__main__":
    server="127.0.0.1"
    user="sa"
    password="fpsoft@123"
    database="MyCustomer"
    # 实例化
    #mssql=MyMSSQL(server=server,database=database)
    mssql=MyMSSQL(server=server,user=user,password=password,database=database)
    # 连接数据库
    (successed,msg)=mssql.connect()
    # print(successed)
    # print(msg)

    # Demo1:查询数据
    sql="SELECT TOP 2 P_CusName,P_Tel FROM Dt_Customers WITH(NOLOCK)"
    print("🌸Demot1:获取客户:")
    humans=mssql.get(sql)
    print(humans)

    # Demo2:执行无参存储过程
    # (successed,msg) = mssql.execProc("Usp_TestNoArgs")
    # print("🌸Demot2:执行无参存储过程(Usp_TestNoArgs):")
    # print(successed,msg)

    # Demo3:执行带参存储过程
    # (successed,msg) = mssql.execProc("Usp_TestWithArgs",(99,"1号机"))
    # print("🌸Demot3:执行带参存储过程(Usp_TestWithArgs):")
    # print(successed,msg)

    # Demo4:执行存储过程并返回数据
    # (successed,msg,datas) = mssql.execProcGet("Usp_Test",("",))
    # print("🌸Demot4:执行存储过程并返回数据(Usp_Test):")
    # print(successed,msg,datas)

    # Demo5:Insert
    # user1 = {"P_UserName": "张三", "P_Age": 25, "P_Email": "Zhang3@example.com"}
    # user2 = {"P_UserName": "李四", "P_Age": 20, "P_Email": "Li4@example.com"}
    # user3 = {"P_UserName": "王五", "P_Age": 18, "P_Email": "Wang5@example.com"}
    # (successed,msg)=mssql.insert("Dt_User",user1)
    # (successed,msg)=mssql.insert("Dt_User",user2)
    # (successed,msg)=mssql.insert("Dt_User",user3)
    # print(successed,msg)

    # Demo6:Update
    # updateData = {"P_Age": 31,"P_Email":"Zhang3@QQ.com"}
    # (successed,msg)=mssql.update("Dt_User", updateData, "P_UserName = ?",('张三',))
    # print(successed,msg)

    # Demo7:Delete
    # (successed,msg)=mssql.delete("Dt_User", "P_UserName = ?", ("王五",))
    # print(successed,msg)

    # Demo8:Select
    # cols=("P_UserName","P_Age")
    # cols=None
    # (successed,msg,data)=mssql.select("Dt_User",cols,"P_UserName = ?",("张三",))
    # print(successed,msg,data)

    # 提交事务
    mssql.commit()
    # 关闭
    mssql.close()

🌺myconfig模块

通过configparser读取配置文件。

使用示例:

from pylhb.myconfig import MyConfig

if __name__ == "__main__":
    config = MyConfig("config.ini")
    config.set("main", "host", "127.0.0.1")
    print(config.get("main", "host"))

🌺mysqlite模块

通过sqlite3访问SQLite数据库。

使用示例:

from pylhb.mysqlite import MySQLite
if __name__ == "__main__":
    # 创建数据库实例
    db = MySQLite("test.db")

    # 连接数据库
    db.connect()

    # 创建表
    columns = {
        "id": "INTEGER PRIMARY KEY AUTOINCREMENT",
        "name": "TEXT NOT NULL",
        "age": "INTEGER",
        "email": "TEXT"
    }
    db.createTable("users", columns)

    # 插入数据
    user1 = {"name": "张三", "age": 25, "email": "zhangsan@example.com"}
    user2 = {"name": "李四", "age": 30, "email": "lisi@example.com"}
    user3 = {"name": "王五", "age": 28, "email": "wangwu@example.com"}

    db.insert("users", user1)
    db.insert("users", user2)
    db.insert("users", user3)

    # 查询所有数据
    print("所有用户:")
    users = db.select("users")
    for user in users:
        print(user)

    # 条件查询
    print("\n年龄大于28的用户:")
    users = db.select("users", where="age > ?", params=(28,))
    for user in users:
        print(user)

    # 更新数据
    update_data = {"age": 31}
    db.update("users", update_data, "name = ?", ("李四",))

    # 查询特定列
    print("\n用户姓名和邮箱:")
    users = db.select("users", columns=["name", "email"])
    for user in users:
        print(user)

    # 删除数据
    db.delete("users", "name = ?", ("王五",))

    # 再次查询所有数据
    print("\n删除后的所有用户:")
    users = db.select("users")
    for user in users:
        print(user)

    # 关闭连接
    db.close()

🌺mylog模块

本地日志操作。

使用示例:

from pylhb.mylog import MyLog

if __name__ == "__main__":
    myLog= MyLog()
    myLog.add("This is a test log entry.")

🌺myjson模块

json配置操作

使用示例:

from pylhb.myjson import MyJSON

if __name__ == "__main__":
    appJson = MyJSON("config.json")
    print(appJson.get("host"))

🌺mysqlite模块

SQLite操作

使用示例:

from pylhb.mysqlite import SQLite

if __name__ == "__main__":
    # 创建数据库实例
    db = SQLite("test.db")

    # 连接数据库
    db.connect()

    # 创建表
    columns = {
        "id": "INTEGER PRIMARY KEY AUTOINCREMENT",
        "name": "TEXT NOT NULL",
        "age": "INTEGER",
        "email": "TEXT"
    }
    db.createTable("users", columns)

    # 插入数据
    user1 = {"name": "张三", "age": 25, "email": "zhangsan@example.com"}
    user2 = {"name": "李四", "age": 30, "email": "lisi@example.com"}
    user3 = {"name": "王五", "age": 28, "email": "wangwu@example.com"}

    db.insert("users", user1)
    db.insert("users", user2)
    db.insert("users", user3)

    # 查询所有数据
    print("所有用户:")
    users = db.select("users")
    for user in users:
        print(user)

    # 条件查询
    print("\n年龄大于28的用户:")
    users = db.select("users", where="age > ?", params=(28,))
    for user in users:
        print(user)

    # 更新数据
    update_data = {"age": 31}
    db.update("users", update_data, "name = ?", ("李四",))

    # 查询特定列
    print("\n用户姓名和邮箱:")
    users = db.select("users", columns=["name", "email"])
    for user in users:
        print(user)

    # 删除数据
    db.delete("users", "name = ?", ("王五",))

    # 再次查询所有数据
    print("\n删除后的所有用户:")
    users = db.select("users")
    for user in users:
        print(user)

    # 关闭连接
    db.close()

🌺mycipher模块

加解密

使用示例:

from pylhb.mycipher import MyAsymClipher,MyXORCipher,MyFernetCipher,MyBlowfishCipher

if __name__ == "__main__":
  # 非对称加密
  ac=MyAsymClipher()
  print(ac.md5("Mr.Lee"))
  print(ac.sha256("Mr.Lee"))
  # XOR对称加解密
  xor=MyXORCipher(key)
  xor.encrypt("") # 加密
  xor.decrypt("") # 解密
  # Fernet对称加解密
  ft=MyFernetCipher(key)
  ft.encrypt("") # 加密
  ft.decrypt("") # 解密
  # Blowfish对称加解密
  bf=MyBlowfishCipher(key)
  bf.encrypt("") # 加密
  bf.decrypt("") # 解密

🌺mysnowflake模块

雪花ID

使用示例:

from pylhb.mysnowflake import MySnowflake

if __name__ == "__main__":
    workerID = 1 # 机器ID
    datacenterID = 1 # 数据中心ID
    snowflake = MySnowflake(workerID, datacenterID)
    # 生成10个ID
    for _ in range(10):
        print(snowflake.generateID())

🌺mydevice模块

设备管理

使用示例:

from pylhb.mydevice import MyDevice

if __name__ == "__main__":
  d=MyDevice()
  print(d.getHostName())
  print(d.getDeviceID())
  print(d.getMAC())
  print(d.getLocalIP())

🌺myspinner模块

进度条

使用示例:

import time
from .myspinner import SpinnerStyle,MySpinner

if __name__ == "__main__":
    # 盲文风格(最漂亮)
    spinner = MySpinner(SpinnerStyle.BRAILLE, "初始化任务...")
    spinner.start()
    time.sleep(1.5)
    spinner.setText("正在下载资源...")
    time.sleep(2)
    spinner.setText("解析数据中...")
    time.sleep(2)
    spinner.setText("生成结果...")
    time.sleep(1.5)
    spinner.stop("任务全部成功完成!")

    # 中断测试
    spinner2 = MySpinner(SpinnerStyle.CLASSIC, "准备测试...")
    spinner2.start()
    time.sleep(1)
    spinner2.setText("即将中断...")
    time.sleep(1)
    spinner2.stop("手动终止成功",showIcon=False)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pylhb-1.6.8.tar.gz (180.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pylhb-1.6.8-py3-none-any.whl (190.9 kB view details)

Uploaded Python 3

File details

Details for the file pylhb-1.6.8.tar.gz.

File metadata

  • Download URL: pylhb-1.6.8.tar.gz
  • Upload date:
  • Size: 180.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pylhb-1.6.8.tar.gz
Algorithm Hash digest
SHA256 191742a8059522ca664ca61b35e63cb73920daf6c889d3061d46e638d959355a
MD5 8f2380220fc534aa9aa09d11d12a2f4d
BLAKE2b-256 c724668bd07e4b21a5ac42b9f6f90e085f28aa4e0c5e7a0fce9c2e2cf8d2b31c

See more details on using hashes here.

File details

Details for the file pylhb-1.6.8-py3-none-any.whl.

File metadata

  • Download URL: pylhb-1.6.8-py3-none-any.whl
  • Upload date:
  • Size: 190.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pylhb-1.6.8-py3-none-any.whl
Algorithm Hash digest
SHA256 736c74293894e42ec94ecfb68c0131d43d8228ae4f85cf5f77167c3bcfa3312f
MD5 a80960e30727b4a9788a87bf5b5b8045
BLAKE2b-256 c3e8c52315c43ae40c1a18c637a5c3a60ce0a4f0695e2169aaf4aae15fc52184

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page