mountains


Namemountains JSON
Version 0.8.8 PyPI version JSON
download
home_pagehttps://github.com/restran/mountains
Summarya util collection for python developing
upload_time2023-10-22 02:22:03
maintainer
docs_urlNone
authorrestran
requires_python
licenseMIT
keywords python utils
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            # mountains

[![travis-ci](https://travis-ci.org/restran/mountains.svg?branch=master)](https://travis-ci.org/restran/mountains) [![Coverage Status](https://coveralls.io/repos/github/restran/mountains/badge.svg?branch=master)](https://coveralls.io/github/restran/mountains?branch=master) [![pypi package](https://img.shields.io/pypi/v/mountains.svg)](https://pypi.python.org/pypi/mountains/)

在开发Python的过程中经常会有一些常用的方法和工具类,因此将这些代码集成在一起,在开发新东西的时候就能直接调用,加速开发。

<img src="docs/icon.png" style="margin-left: auto; margin-right: auto; text-align: center; display: block;">

## 安装

    pip install mountains

## 功能

1. Python 2-3 兼容,大部分代码都尽可能做了兼容
2. 日期转换,各种日期、字符串、时间戳直接的转换
3. SSHClient
4. Tornado 的异步请求
5. Random HTTP User Agent
6. 文件、Excel、json 读写 
7. ...


### 日期转换

datetime、time、时间戳、日期字符串之间的转换

```python

import time
from datetime import datetime
from mountains.datetime import converter

date_str = '2016-10-30 12:30:30'
dt = datetime(year=2016, month=10, day=30, hour=12, minute=30, second=30)
t = dt.timetuple()
ts = int(time.mktime(t))
ts_ms = int(time.mktime(t) * 1000)

# 字符串转 datetime
dt = converter.str2datetime(date_str)
# 字符串转 time
converter.str2time(date_str)
# 日期字符串转时间戳,结果为秒
converter.str2timestamp(date_str)
# 日期字符串转时间戳,结果为毫秒
converter.str2timestamp(date_str, millisecond=True)
# datetime 转字符串,默认格式 %Y-%m-%d %H:%M:%S
converter.datetime2str(dt)
# datetime 转字符串,指定格式
converter.datetime2str(dt, '%Y-%m-%d')
```

###  日志功能 

对原生的 logging 进行了封装,使用起来更简单

```python
from mountains import logging
from mountains.logging import StreamHandler, FileHandler, RotatingFileHandler, TimedRotatingFileHandler

# 配置日志,输出到控制台、保存到文件、日志级别、输出格式等,文件默认保存到 log.txt
logging.init_log(StreamHandler(format=logging.FORMAT_SIMPLE), FileHandler(format=logging.FORMAT_VERBOSE, level=logging.DEBUG))
# RotatingFileHandler 按文件大小分割日志文件
logging.init_log(StreamHandler(format=logging.FORMAT_SIMPLE), RotatingFileHandler(format=logging.FORMAT_VERBOSE, level=logging.DEBUG))
# TimedRotatingFileHandler 按时间分割日志文件
logging.init_log(StreamHandler(format=logging.FORMAT_SIMPLE), TimedRotatingFileHandler(format=logging.FORMAT_VERBOSE, level=logging.DEBUG))

# 使用方法与原生的 logging 一样
logger = logging.getLogger(__name__)
logger.debug('hello')
```

### Excel 读写

```python
from mountains.file.excel import read_excel, write_excel, edit_excel
# 读 Excel 文件
data = read_excel('filename.xlsx')

# 写新的 Excel
excel_data = [
    {
        'col1': '123',
        'col2': '456'
    },
    {
        'col1': '123',
        'col2': '456'
    },
]

headers = ['col1', 'col2']
write_excel(headers, excel_data, 'filename.xlsx')

# 编辑 Excel,打开已有的 Excel,往里面填充数据
edit_data = {
    'I2': '123'
}
edit_excel('test.xlsx', sheet_index=0, data=edit_data, output_filename='new_test.xlsx')
```




            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/restran/mountains",
    "name": "mountains",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python utils",
    "author": "restran",
    "author_email": "grestran@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/07/f0/59b404166be61b303a47bb5c3fa08d21d95606275373125129cef35f4101/mountains-0.8.8.tar.gz",
    "platform": "any",
    "description": "# mountains\n\n[![travis-ci](https://travis-ci.org/restran/mountains.svg?branch=master)](https://travis-ci.org/restran/mountains) [![Coverage Status](https://coveralls.io/repos/github/restran/mountains/badge.svg?branch=master)](https://coveralls.io/github/restran/mountains?branch=master) [![pypi package](https://img.shields.io/pypi/v/mountains.svg)](https://pypi.python.org/pypi/mountains/)\n\n\u5728\u5f00\u53d1Python\u7684\u8fc7\u7a0b\u4e2d\u7ecf\u5e38\u4f1a\u6709\u4e00\u4e9b\u5e38\u7528\u7684\u65b9\u6cd5\u548c\u5de5\u5177\u7c7b\uff0c\u56e0\u6b64\u5c06\u8fd9\u4e9b\u4ee3\u7801\u96c6\u6210\u5728\u4e00\u8d77\uff0c\u5728\u5f00\u53d1\u65b0\u4e1c\u897f\u7684\u65f6\u5019\u5c31\u80fd\u76f4\u63a5\u8c03\u7528\uff0c\u52a0\u901f\u5f00\u53d1\u3002\n\n<img src=\"docs/icon.png\" style=\"margin-left: auto; margin-right: auto; text-align: center; display: block;\">\n\n## \u5b89\u88c5\n\n    pip install mountains\n\n## \u529f\u80fd\n\n1. Python 2-3 \u517c\u5bb9\uff0c\u5927\u90e8\u5206\u4ee3\u7801\u90fd\u5c3d\u53ef\u80fd\u505a\u4e86\u517c\u5bb9\n2. \u65e5\u671f\u8f6c\u6362\uff0c\u5404\u79cd\u65e5\u671f\u3001\u5b57\u7b26\u4e32\u3001\u65f6\u95f4\u6233\u76f4\u63a5\u7684\u8f6c\u6362\n3. SSHClient\n4. Tornado \u7684\u5f02\u6b65\u8bf7\u6c42\n5. Random HTTP User Agent\n6. \u6587\u4ef6\u3001Excel\u3001json \u8bfb\u5199 \n7. ...\n\n\n### \u65e5\u671f\u8f6c\u6362\n\ndatetime\u3001time\u3001\u65f6\u95f4\u6233\u3001\u65e5\u671f\u5b57\u7b26\u4e32\u4e4b\u95f4\u7684\u8f6c\u6362\n\n```python\n\nimport time\nfrom datetime import datetime\nfrom mountains.datetime import converter\n\ndate_str = '2016-10-30 12:30:30'\ndt = datetime(year=2016, month=10, day=30, hour=12, minute=30, second=30)\nt = dt.timetuple()\nts = int(time.mktime(t))\nts_ms = int(time.mktime(t) * 1000)\n\n# \u5b57\u7b26\u4e32\u8f6c datetime\ndt = converter.str2datetime(date_str)\n# \u5b57\u7b26\u4e32\u8f6c time\nconverter.str2time(date_str)\n# \u65e5\u671f\u5b57\u7b26\u4e32\u8f6c\u65f6\u95f4\u6233\uff0c\u7ed3\u679c\u4e3a\u79d2\nconverter.str2timestamp(date_str)\n# \u65e5\u671f\u5b57\u7b26\u4e32\u8f6c\u65f6\u95f4\u6233\uff0c\u7ed3\u679c\u4e3a\u6beb\u79d2\nconverter.str2timestamp(date_str, millisecond=True)\n# datetime \u8f6c\u5b57\u7b26\u4e32\uff0c\u9ed8\u8ba4\u683c\u5f0f %Y-%m-%d %H:%M:%S\nconverter.datetime2str(dt)\n# datetime \u8f6c\u5b57\u7b26\u4e32\uff0c\u6307\u5b9a\u683c\u5f0f\nconverter.datetime2str(dt, '%Y-%m-%d')\n```\n\n###  \u65e5\u5fd7\u529f\u80fd \n\n\u5bf9\u539f\u751f\u7684 logging \u8fdb\u884c\u4e86\u5c01\u88c5\uff0c\u4f7f\u7528\u8d77\u6765\u66f4\u7b80\u5355\n\n```python\nfrom mountains import logging\nfrom mountains.logging import StreamHandler, FileHandler, RotatingFileHandler, TimedRotatingFileHandler\n\n# \u914d\u7f6e\u65e5\u5fd7\uff0c\u8f93\u51fa\u5230\u63a7\u5236\u53f0\u3001\u4fdd\u5b58\u5230\u6587\u4ef6\u3001\u65e5\u5fd7\u7ea7\u522b\u3001\u8f93\u51fa\u683c\u5f0f\u7b49\uff0c\u6587\u4ef6\u9ed8\u8ba4\u4fdd\u5b58\u5230 log.txt\nlogging.init_log(StreamHandler(format=logging.FORMAT_SIMPLE), FileHandler(format=logging.FORMAT_VERBOSE, level=logging.DEBUG))\n# RotatingFileHandler \u6309\u6587\u4ef6\u5927\u5c0f\u5206\u5272\u65e5\u5fd7\u6587\u4ef6\nlogging.init_log(StreamHandler(format=logging.FORMAT_SIMPLE), RotatingFileHandler(format=logging.FORMAT_VERBOSE, level=logging.DEBUG))\n# TimedRotatingFileHandler \u6309\u65f6\u95f4\u5206\u5272\u65e5\u5fd7\u6587\u4ef6\nlogging.init_log(StreamHandler(format=logging.FORMAT_SIMPLE), TimedRotatingFileHandler(format=logging.FORMAT_VERBOSE, level=logging.DEBUG))\n\n# \u4f7f\u7528\u65b9\u6cd5\u4e0e\u539f\u751f\u7684 logging \u4e00\u6837\nlogger = logging.getLogger(__name__)\nlogger.debug('hello')\n```\n\n### Excel \u8bfb\u5199\n\n```python\nfrom mountains.file.excel import read_excel, write_excel, edit_excel\n# \u8bfb Excel \u6587\u4ef6\ndata = read_excel('filename.xlsx')\n\n# \u5199\u65b0\u7684 Excel\nexcel_data = [\n    {\n        'col1': '123',\n        'col2': '456'\n    },\n    {\n        'col1': '123',\n        'col2': '456'\n    },\n]\n\nheaders = ['col1', 'col2']\nwrite_excel(headers, excel_data, 'filename.xlsx')\n\n# \u7f16\u8f91 Excel\uff0c\u6253\u5f00\u5df2\u6709\u7684 Excel\uff0c\u5f80\u91cc\u9762\u586b\u5145\u6570\u636e\nedit_data = {\n    'I2': '123'\n}\nedit_excel('test.xlsx', sheet_index=0, data=edit_data, output_filename='new_test.xlsx')\n```\n\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "a util collection for python developing",
    "version": "0.8.8",
    "project_urls": {
        "Homepage": "https://github.com/restran/mountains"
    },
    "split_keywords": [
        "python",
        "utils"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3956226c68149eac1425d13a3c1dc0beb35ecbfe381d5a3f0e0793fc5ff53175",
                "md5": "a7347719d62490f3c2442cde55431162",
                "sha256": "85bf8a085f1609537e44dea97b2fde21841cac1830e69019e70c35eda277a714"
            },
            "downloads": -1,
            "filename": "mountains-0.8.8-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a7347719d62490f3c2442cde55431162",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 158091,
            "upload_time": "2023-10-22T02:22:00",
            "upload_time_iso_8601": "2023-10-22T02:22:00.370521Z",
            "url": "https://files.pythonhosted.org/packages/39/56/226c68149eac1425d13a3c1dc0beb35ecbfe381d5a3f0e0793fc5ff53175/mountains-0.8.8-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "07f059b404166be61b303a47bb5c3fa08d21d95606275373125129cef35f4101",
                "md5": "e53f0141315aaa274df171529d426122",
                "sha256": "ad2400eda3e9f07b47c7cc69ade07aaa17049e867988b892384e723c7340ad33"
            },
            "downloads": -1,
            "filename": "mountains-0.8.8.tar.gz",
            "has_sig": false,
            "md5_digest": "e53f0141315aaa274df171529d426122",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 139749,
            "upload_time": "2023-10-22T02:22:03",
            "upload_time_iso_8601": "2023-10-22T02:22:03.741231Z",
            "url": "https://files.pythonhosted.org/packages/07/f0/59b404166be61b303a47bb5c3fa08d21d95606275373125129cef35f4101/mountains-0.8.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-22 02:22:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "restran",
    "github_project": "mountains",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": false,
    "requirements": [],
    "lcname": "mountains"
}
        
Elapsed time: 0.35075s