12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #!/usr/bin/env python
- # -*- encoding: utf-8 -*-
- '''
- @Contact : liuyuqi.gov@msn.cn
- @Time : 2023/07/11 20:18:28
- @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
- @Desc : read and write config.ini
- '''
- import os,sys,re,configparser
- file_path = "../conf/config.ini"
- def write():
- cf = configparser.ConfigParser()
- cf.read(file_path)
- if not cf.has_section("mail"):
- cf.add_section("mail")
- cf.set("mail", "host", "smtp.qq.com")
- cf.set("mail", "user", "xx@qq.com")
- cf.set("mail", "password", "12346")
- cf.set("mail", "sender", "xx@qq.com")
- cf.set("mail", "receviers", "xx@qq.com;xx@qq.com")
- if not cf.has_section("db"):
- cf.add_section("db")
- cf.set("db", "db_port", "3307")
- cf.write(open(file_path, "w"))
- if not cf.has_section("account"):
- cf.add_section("account")
- cf.set("account", "db_port", "3307")
- cf.write(open(file_path, "w"))
- def read():
- cf = configparser.ConfigParser()
- cf.read(file_path)
- opt_val = cf.get("db", "db_port")
- print(opt_val)
- kvs = cf.items("db")
- print(kvs)
- if __name__=='__main__':
- # read()
- import time
- # 打印时间戳,整形
- print(int(time.time()))
|