Skip to main content

maxwin团队常用的utils

Project description

rst file editor

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.39

  • DatabaseConf增加判断是否db_have_changed

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

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.39.tar.gz (14.2 kB view details)

Uploaded Source

File details

Details for the file mwutils-0.1.39.tar.gz.

File metadata

  • Download URL: mwutils-0.1.39.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for mwutils-0.1.39.tar.gz
Algorithm Hash digest
SHA256 9aca908b2af7ba173ad3c78b20f5367ad37af299f2b8aefabe3c37fa6183cdca
MD5 ccd1f414ea1aa85c4810fac8ef3652a1
BLAKE2b-256 ad1c7c70e5d5db14b29c1a36b9821ce69f95eb3a2307d003b73f8ef87895ebc2

See more details on using hashes here.

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