Coder Social home page Coder Social logo

easyutils's Introduction

easyutils

希望能提供一些股市常用的接口,减少重复劳动

Install

pip install easyutils

Usage

import easyutils
easyuitls.is_holiday_today()

is_holiday

def is_holiday(day):
    """
    判断是否节假日
    :param day: 日期, 格式为 '20160404'
    :return: Bool

is_holiday_today

def is_holiday_today():
    """
    判断今天是否时节假日
    :return: bool
    """

is_tradetime_now

def is_tradetime_now():
    """
    判断目前是不是交易时间, 并没有对节假日做处理
    :return: bool

get_stock_type

def get_stock_type(stock_code):
    """判断股票ID对应的证券市场
    匹配规则
    ['50', '51', '60', '90', '110'] 为 sh
    ['00', '13', '18', '15', '16', '18', '20', '30', '39', '115'] 为 sz
    ['5', '6', '9'] 开头的为 sh, 其余为 sz
    :param stock_code:股票ID, 若以 'sz', 'sh' 开头直接返回对应类型,否则使用内置规则判断
    :return 'sh' or 'sz'"""

get_code_type

def get_code_type(code):
    """
    判断代码是属于那种类型,目前仅支持 ['fund', 'stock']
    :return str 返回code类型, fund 基金 stock 股票
    """

get_all_stock_codes

def get_all_stock_codes():
    """获取所有股票 ID"""

easyutils's People

Contributors

shidenggui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

easyutils's Issues

推荐一个计算节假日的函数

from business_calendar import Calendar, MO, TU, WE, TH, FR, SA, SU
def cal_days(day1, day2, workdays, holidays):
'''
day1: str, 第一个日期 '2019-06-04'
day2: str, 第二个日期 '2019-06-05'
workdays: list, 工作日 [MO, TU, WE, TH, FR]
holidays: list, 假期 ['2019-01-01','2019-05-01',.... ]
2019年假期 ['2019-01-01', '2019-02-04', '2019-02-05', '2019-02-06',
'2019-02-07', '2019-02-08', '2019-04-05', '2019-05-01',
'2019-05-02', '2019-05-03', '2019-06-07', '2019-09-13',
'2019-10-01', '2019-10-02', '2019-10-03', '2019-10-04,
'2019-10-07', '2020-01-01']
因为有警告信息, 所以添加了一个2020年元旦在假期里
'''

if (check_type(day1, 'str') and check_type(day2, 'str') and check_type(workdays, 'list')
    and check_type(holidays, 'list') and all([day1, day2, workdays, holidays])):
    try:
        day1 = parse(day1)
        day2 = parse(day2)
        cal = Calendar(workdays= workdays , holidays= holidays)
        workdays = cal.busdaycount(day1, day2)
        return workdays
    except Exception as e:
        print('\033[0;31;0m cal_days does not work , will return zero !\033[0m')
        return 0
else:
    print('\033[0;31;0m please check the data type for cal_days function\033[0m')

推荐一个计算节假日的函数

from business_calendar import Calendar, MO, TU, WE, TH, FR, SA, SU
def cal_days(day1, day2, workdays, holidays):
'''
day1: str, 第一个日期 '2019-06-04'
day2: str, 第二个日期 '2019-06-05'
workdays: list, 工作日 [MO, TU, WE, TH, FR]
holidays: list, 假期 ['2019-01-01','2019-05-01',.... ]
2019年假期 ['2019-01-01', '2019-02-04', '2019-02-05', '2019-02-06',
'2019-02-07', '2019-02-08', '2019-04-05', '2019-05-01',
'2019-05-02', '2019-05-03', '2019-06-07', '2019-09-13',
'2019-10-01', '2019-10-02', '2019-10-03', '2019-10-04,
'2019-10-07', '2020-01-01']
因为有警告信息, 所以添加了一个2020年元旦在假期里
'''

if (check_type(day1, 'str') and check_type(day2, 'str') and check_type(workdays, 'list')
    and check_type(holidays, 'list') and all([day1, day2, workdays, holidays])):
    try:
        day1 = parse(day1)
        day2 = parse(day2)
        cal = Calendar(workdays= workdays , holidays= holidays)
        workdays = cal.busdaycount(day1, day2)
        return workdays
    except Exception as e:
        print('\033[0;31;0m cal_days does not work , will return zero !\033[0m')
        return 0
else:
    print('\033[0;31;0m please check the data type for cal_days function\033[0m')

您好,安装easyutils的时候提示错误

F:\py\easyquant>pip install easyutils
Collecting easyutils
Using cached easyutils-0.0.2-py3-none-any.whl
Collecting pyquery (from easyutils)
Using cached pyquery-1.2.13.tar.gz
Requirement already satisfied (use --upgrade to upgrade): requests in f:\python35-32\lib\site-packages (from easyutils)
Collecting lxml>=2.1 (from pyquery->easyutils)
Using cached lxml-3.6.0.tar.gz
Collecting cssselect>0.7.9 (from pyquery->easyutils)
Using cached cssselect-0.9.2-py2.py3-none-any.whl
Installing collected packages: lxml, cssselect, pyquery, easyutils
Running setup.py install for lxml ... error
Complete output from command f:\python35-32\python.exe -u -c "import setuptools, tokenize;file='C:\Users\ADMINI1\AppData\Local\Temp\pip-build-sbh6ud56\lxml\setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record C:\Users\ADMINI1\AppData\Local\Temp\pip-xcpdeble-record\install-record.txt --single-version-externally-managed --compile:
Building lxml version 3.6.0.
Building without Cython.
ERROR: b"'xslt-config' \xb2\xbb\xca\xc7\xc4\xda\xb2\xbf\xbb\xf2\xcd\xe2\xb2\xbf\xc3\xfc\xc1\xee\xa3\xac\xd2\xb2\xb2\xbb\xca\xc7\xbf\xc9\xd4\xcb\xd0\xd0\xb5\xc4\xb3\xcc\xd0\xf2\r\n\xbb\xf2\xc5\xfa\xb4\xa6\xc0\xed\xce\xc4\xbc\xfe\xa1\xa3\r\n"
** make sure the development packages of libxml2 and libxslt are installed **

Using build configuration of libxslt
running install
running build
running build_py
creating build
creating build\lib.win32-3.5
creating build\lib.win32-3.5\lxml
copying src\lxml\builder.py -> build\lib.win32-3.5\lxml
copying src\lxml\cssselect.py -> build\lib.win32-3.5\lxml
copying src\lxml\doctestcompare.py -> build\lib.win32-3.5\lxml
copying src\lxml\ElementInclude.py -> build\lib.win32-3.5\lxml
copying src\lxml\pyclasslookup.py -> build\lib.win32-3.5\lxml
copying src\lxml\sax.py -> build\lib.win32-3.5\lxml
copying src\lxml\usedoctest.py -> build\lib.win32-3.5\lxml
copying src\lxml\_elementpath.py -> build\lib.win32-3.5\lxml
copying src\lxml\__init__.py -> build\lib.win32-3.5\lxml
creating build\lib.win32-3.5\lxml\includes
copying src\lxml\includes\__init__.py -> build\lib.win32-3.5\lxml\includes
creating build\lib.win32-3.5\lxml\html
copying src\lxml\html\builder.py -> build\lib.win32-3.5\lxml\html
copying src\lxml\html\clean.py -> build\lib.win32-3.5\lxml\html
copying src\lxml\html\defs.py -> build\lib.win32-3.5\lxml\html
copying src\lxml\html\diff.py -> build\lib.win32-3.5\lxml\html
copying src\lxml\html\ElementSoup.py -> build\lib.win32-3.5\lxml\html
copying src\lxml\html\formfill.py -> build\lib.win32-3.5\lxml\html
copying src\lxml\html\html5parser.py -> build\lib.win32-3.5\lxml\html
copying src\lxml\html\soupparser.py -> build\lib.win32-3.5\lxml\html
copying src\lxml\html\usedoctest.py -> build\lib.win32-3.5\lxml\html
copying src\lxml\html\_diffcommand.py -> build\lib.win32-3.5\lxml\html
copying src\lxml\html\_html5builder.py -> build\lib.win32-3.5\lxml\html
copying src\lxml\html\_setmixin.py -> build\lib.win32-3.5\lxml\html
copying src\lxml\html\__init__.py -> build\lib.win32-3.5\lxml\html
creating build\lib.win32-3.5\lxml\isoschematron
copying src\lxml\isoschematron\__init__.py -> build\lib.win32-3.5\lxml\isoschematron
copying src\lxml\lxml.etree.h -> build\lib.win32-3.5\lxml
copying src\lxml\lxml.etree_api.h -> build\lib.win32-3.5\lxml
copying src\lxml\includes\c14n.pxd -> build\lib.win32-3.5\lxml\includes
copying src\lxml\includes\config.pxd -> build\lib.win32-3.5\lxml\includes
copying src\lxml\includes\dtdvalid.pxd -> build\lib.win32-3.5\lxml\includes
copying src\lxml\includes\etreepublic.pxd -> build\lib.win32-3.5\lxml\includes
copying src\lxml\includes\htmlparser.pxd -> build\lib.win32-3.5\lxml\includes
copying src\lxml\includes\relaxng.pxd -> build\lib.win32-3.5\lxml\includes
copying src\lxml\includes\schematron.pxd -> build\lib.win32-3.5\lxml\includes
copying src\lxml\includes\tree.pxd -> build\lib.win32-3.5\lxml\includes
copying src\lxml\includes\uri.pxd -> build\lib.win32-3.5\lxml\includes
copying src\lxml\includes\xinclude.pxd -> build\lib.win32-3.5\lxml\includes
copying src\lxml\includes\xmlerror.pxd -> build\lib.win32-3.5\lxml\includes
copying src\lxml\includes\xmlparser.pxd -> build\lib.win32-3.5\lxml\includes
copying src\lxml\includes\xmlschema.pxd -> build\lib.win32-3.5\lxml\includes
copying src\lxml\includes\xpath.pxd -> build\lib.win32-3.5\lxml\includes
copying src\lxml\includes\xslt.pxd -> build\lib.win32-3.5\lxml\includes
copying src\lxml\includes\etree_defs.h -> build\lib.win32-3.5\lxml\includes
copying src\lxml\includes\lxml-version.h -> build\lib.win32-3.5\lxml\includes
creating build\lib.win32-3.5\lxml\isoschematron\resources
creating build\lib.win32-3.5\lxml\isoschematron\resources\rng
copying src\lxml\isoschematron\resources\rng\iso-schematron.rng -> build\lib.win32-3.5\lxml\isoschematron\resources\rng
creating build\lib.win32-3.5\lxml\isoschematron\resources\xsl
copying src\lxml\isoschematron\resources\xsl\RNG2Schtrn.xsl -> build\lib.win32-3.5\lxml\isoschematron\resources\xsl
copying src\lxml\isoschematron\resources\xsl\XSD2Schtrn.xsl -> build\lib.win32-3.5\lxml\isoschematron\resources\xsl
creating build\lib.win32-3.5\lxml\isoschematron\resources\xsl\iso-schematron-xslt1
copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_abstract_expand.xsl -> build\lib.win32-3.5\lxml\isoschematron\resources\xsl\iso-schematron-xslt1
copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_dsdl_include.xsl -> build\lib.win32-3.5\lxml\isoschematron\resources\xsl\iso-schematron-xslt1
copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_schematron_message.xsl -> build\lib.win32-3.5\lxml\isoschematron\resources\xsl\iso-schematron-xslt1
copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_schematron_skeleton_for_xslt1.xsl -> build\lib.win32-3.5\lxml\isoschematron\resources\xsl\iso-schematron-xslt1
copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_svrl_for_xslt1.xsl -> build\lib.win32-3.5\lxml\isoschematron\resources\xsl\iso-schematron-xslt1
copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\readme.txt -> build\lib.win32-3.5\lxml\isoschematron\resources\xsl\iso-schematron-xslt1
running build_ext
building 'lxml.etree' extension
error: Unable to find vcvarsall.bat

请问这是什么原因呢?初学,百思无解

安装不了easyutils

终端执行
sudo pip install easyutils
然后报这个

Downloading/unpacking easyutils
Downloading easyutils-0.0.2.tar.gz
Running setup.py (path:/tmp/pip_build_root/easyutils/setup.py) egg_info for package easyutils
Traceback (most recent call last):
File "", line 17, in
File "/tmp/pip_build_root/easyutils/setup.py", line 3, in
import easyutils
File "easyutils/init.py", line 1, in
from . import stock
File "easyutils/stock.py", line 7
SyntaxError: Non-ASCII character '\xe5' in file easyutils/stock.py on line 7, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
Complete output from command python setup.py egg_info:
Traceback (most recent call last):

File "", line 17, in

File "/tmp/pip_build_root/easyutils/setup.py", line 3, in

import easyutils

File "easyutils/init.py", line 1, in

from . import stock

File "easyutils/stock.py", line 7

SyntaxError: Non-ASCII character '\xe5' in file easyutils/stock.py on line 7, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

我一愣,跑去 安装stock
➜ web-scraper git:(master) ✗ sudo pip install stock
Downloading/unpacking stock
Downloading stock-0.8.tar.gz
Running setup.py (path:/tmp/pip_build_root/stock/setup.py) egg_info for package stock

file stock.py (for module stock) not found
warning: no files found matching 'test_requirements.txt'

Downloading/unpacking flask (from stock)
Downloading Flask-0.11.1-py2.py3-none-any.whl (80kB): 0bytes downloaded
Cleaning up...
Exception:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 278, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1198, in prepare_files
do_download,
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1376, in unpack_url
self.session,
File "/usr/lib/python2.7/dist-packages/pip/download.py", line 572, in unpack_http_url
download_hash = _download_url(resp, link, temp_location)
File "/usr/lib/python2.7/dist-packages/pip/download.py", line 433, in _download_url
for chunk in resp_read(4096):
File "/usr/lib/python2.7/dist-packages/pip/download.py", line 421, in resp_read
chunk_size, decode_content=False):
File "/usr/share/python-wheels/urllib3-1.7.1-py2.py3-none-any.whl/urllib3/response.py", line 225, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/usr/share/python-wheels/urllib3-1.7.1-py2.py3-none-any.whl/urllib3/response.py", line 174, in read
data = self._fp.read(amt)
File "/usr/lib/python2.7/httplib.py", line 573, in read
s = self.fp.read(amt)
File "/usr/lib/python2.7/socket.py", line 380, in read
data = self._sock.recv(left)
File "/usr/lib/python2.7/ssl.py", line 341, in recv
return self.read(buflen)
File "/usr/lib/python2.7/ssl.py", line 260, in read
return self._sslobj.read(len)
SSLError: The read operation timed out

Storing debug log for failure in /home/sunshine/.pip/pip.log

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.