Skip to main content

maxwin团队常用的utils

Project description

mwutils

maxwin 团队开发框架utils

为了兼容windows开发环境,日期时间parse模块采用python-dateutil,但ciso8601的pars性能比之快百倍,如果是linux下安装,请先安装

“pip install ciso8601”

安装

$ pip install mwutils

mw_time.py 单元

from mwutils.mw_time import *

# 字符串转为本地日期时间

print(str2datetime('2018-01-01'))

print(str2datetime('2018-01-01T12:00:00'))

print(str2datetime('2018-01-01T12:00:00Z'))

print(str2datetime('2018-01-01T12:00:00+02:00'))

# 字符串转日期

print(str2date('2018-01-01'))

# 字符串转时间

print(str2time('11:11:11'))

# 日期时间转iso8601 tz 格式字符串

print(datetime2isostr(datetime.now()))

# 日期时间转本地日期时间字符串

print(datetime2str(datetime.now()))

# 日期时间转integer时间戳

print(datetime2timestamp(datetime.now()))

# 时间戳转本地日期时间

print(timestamp2datetimestr(1515579120.0))

# get locale timezone

print(get_locale_timezone())

# min_time(dt1,dt2),max_time(dt1,dt2) 两个日期时间取最小和最大时间

utils.py 单元

from mwutils.utils import getConfig,hostname

# 读取config.ini

print(getConfig('./config.ini')

# 获取电脑的 hostname

print(hostname)

mw_consul.py 单元

> 访问consul 中的常用服务配置

from mw_consul import *

# reg_service : 向consul中注册服务

# dereg_service: 注销服务

# AgentConf() : 獲取本機agent

# RedisConf() : redis的配置

# RedisConfMaster(): master redis的配置

# RedisConfSlave():离本机最近的slave redis 配置

# DatabaseConf('maxbus'):获取tag=maxbus的database服务的配置

# KongConf():取kong的配置

# KongAdminConf():取kong admin 的配置

# KafkaConf():取kafka的配置

# Cassandra():取Cassandra的配置

# ServiceConf(service_name,tag):取设定tag,service_name的服务配置

cache.py 单元

> sigleton,内存中只会创建一个实例

from cache import Cached

# # Example

class Spam(metaclass=Cached):

  def __init__(self, name):

      print('Creating Spam({!r})'.format(name))

      self.name = name

sendemail.py 单元

> 发送邮件

from sendemail import Emailsender

Changes

0.1.33

  • Redis 配置支持哨兵模式

0.1.30

  • 解决linux 下 str2datetime(‘20201009101112’) 会报错的问题

0.1.29

windows下用dateutil做时间字串parse

0.1.28

修正从consul的kv中取redis db 失败的问题

0.1.27 (2018-12-19)

  • 重整mw_consul单元的类

0.1.24 (2018-10-31)

  • 解决非Unicode中文环境下不能安装的问题

0.1.23 (2018-10-29)

  • 在mw_time单元中增加对iso6801日期时间的支持,增加了部分常用日期时间的处理

  • 删除 register_kong.py

Platform: UNKNOWN Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python :: 3.6

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

mwutils-0.1.35.tar.gz (13.5 kB view hashes)

Uploaded Source

Supported by

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