Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Stock.highprice and Stock.lowprice #26

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
grs 台灣上市上櫃股票價格擷取
===============================

.. image:: https://secure.travis-ci.org/toomore/grs.png?branch=master
.. image:: https://travis-ci.org/toomore/grs.svg?branch=master
:target: http://travis-ci.org/toomore/grs

.. image:: https://pypip.in/d/grs/badge.png
.. image:: https://img.shields.io/pypi/dm/grs.svg?maxAge=2592000
:target: https://pypi.python.org/pypi/grs

.. image:: https://pypip.in/v/grs/badge.png
.. image:: https://img.shields.io/pypi/v/grs.svg?maxAge=2592000
:target: https://pypi.python.org/pypi/grs

.. image:: https://pypip.in/wheel/grs/badge.png
.. image:: https://img.shields.io/pypi/wheel/grs.svg?maxAge=2592000
:target: https://pypi.python.org/pypi/grs

.. image:: https://pypip.in/license/grs/badge.png
.. image:: https://img.shields.io/pypi/l/grs.svg?maxAge=2592000
:target: https://pypi.python.org/pypi/grs

主要開發擷取台灣股市(TWSE)股價資料
Expand All @@ -27,7 +27,7 @@ grs 台灣上市上櫃股票價格擷取
-----------------------------

:Authors: Toomore Chiang
:Version: 0.6.2 of 2015/03/20
:Version: 0.7.0 of 2016/09/11
:Python Version: Python 2.7
:Docs: http://grs-docs.toomore.net/

Expand Down Expand Up @@ -286,6 +286,11 @@ Quick Start
Change Logs
-----------------------------

0.7.0 2016/09/11
====================================

- 修正:上市(TWSE)擷取連結

0.6.2 2015/03/20
====================================

Expand Down
16 changes: 9 additions & 7 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ Welcome to grs's documentation!
grs 台灣上市上櫃股票價格擷取
=================================

.. image:: https://secure.travis-ci.org/toomore/grs.png?branch=master
.. image:: https://travis-ci.org/toomore/grs.svg?branch=master
:target: http://travis-ci.org/toomore/grs

.. image:: https://pypip.in/d/grs/badge.png
.. image:: https://img.shields.io/pypi/dm/grs.svg?maxAge=2592000
:target: https://pypi.python.org/pypi/grs

.. image:: https://pypip.in/v/grs/badge.png
.. image:: https://img.shields.io/pypi/v/grs.svg?maxAge=2592000
:target: https://pypi.python.org/pypi/grs

.. image:: https://pypip.in/wheel/grs/badge.png
.. image:: https://img.shields.io/pypi/wheel/grs.svg?maxAge=2592000
:target: https://pypi.python.org/pypi/grs

.. image:: https://pypip.in/license/grs/badge.png
.. image:: https://img.shields.io/pypi/l/grs.svg?maxAge=2592000
:target: https://pypi.python.org/pypi/grs

主要開發擷取台灣股市(TWSE)股價資料
Expand All @@ -35,7 +35,7 @@ grs 台灣上市上櫃股票價格擷取
-----------------------------

:Authors: Toomore Chiang
:Version: 0.6.2 of 2015/03/19
:Version: 0.7.0 of 2016/09/11
:Python Version: Python 2.7
:Docs: http://grs-docs.toomore.net/

Expand Down Expand Up @@ -83,6 +83,9 @@ Feature
Change Logs
-----------------------------

* 0.7.0 2016/09/11
- 修正:上市(TWSE)擷取連結

* 0.6.2 2015/03/20
- 修正:上櫃(OTC)擷取連結

Expand Down Expand Up @@ -164,4 +167,3 @@ Indices and tables
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

4 changes: 2 additions & 2 deletions grs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
# THE SOFTWARE.

__title__ = 'grs'
__version__ = '0.6.2'
__version__ = '0.7.0'
__author__ = 'Toomore Chiang'
__license__ = 'MIT'
__copyright__ = 'Copyright (C) 2012, 2013, 2014 Toomore Chiang'
__copyright__ = 'Copyright (C) 2012, 2013, 2014, 2015, 2016 Toomore Chiang'


from .best_buy_or_sell import BestFourPoint
Expand Down
41 changes: 27 additions & 14 deletions grs/fetch_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ def to_list(self, csv_file):
tolist.append(i)
if self._twse:
if tolist:
self.__info = (tolist[0][0].split(' ')[1],
tolist[0][0].split(' ')[2].decode('cp950'))
_stock_info = tolist[0][0].split(' ')[1].strip()
self.__info = (_stock_info[:4],
_stock_info[4:].decode('utf-8'))
self.__raw_rows_name = tolist[1]
return tuple(tolist[2:])
return tuple([])
Expand Down Expand Up @@ -194,18 +195,14 @@ def fetch_data(self, stock_no, nowdatetime):
:param datetime nowdatetime: 此刻時間
:rtype: list
"""
url = (
'/ch/trading/exchange/' +
'STOCK_DAY/STOCK_DAY_print.php?genpage=genpage/' +
'Report%(year)d%(mon)02d/%(year)d%(mon)02d_F3_1_8_%(stock)s.php' +
'&type=csv&r=%(rand)s') % {'year': nowdatetime.year,
'mon': nowdatetime.month,
'stock': stock_no,
'rand': random.randrange(1, 1000000)}
logging.info(url)
result = TWSE_CONNECTIONS.urlopen('GET', url)
csv_files = csv.reader(StringIO(result.data))
self.__url.append(TWSE_HOST + url)
result = TWSE_CONNECTIONS.request('POST',
'/ch/trading/exchange/STOCK_DAY/STOCK_DAYMAIN.php',
fields={'download': 'csv',
'query_year': nowdatetime.year,
'query_month': nowdatetime.month,
'CO_ID': stock_no})
_de = result.data.decode('cp950', 'ignore')
csv_files = csv.reader(StringIO(_de.encode('utf-8')))
return csv_files


Expand Down Expand Up @@ -398,6 +395,22 @@ def openprice(self):
"""
return self.__serial_price(3)

@property
def highprice(self):
""" highest股價序列

:rtype: list
"""
return self.__serial_price(4)

@property
def lowprice(self):
""" lowest股價序列

:rtype: list
"""
return self.__serial_price(5)

@property
def value(self):
""" 成交量序列(張)
Expand Down
2 changes: 1 addition & 1 deletion test_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_countdown():
@staticmethod
def test_taiwan_50():
stock = grs.Stock('0050')
assert u'台灣50' == stock.info[1]
assert u'元大台灣50' == stock.info[1]
try:
stock = grs.Stock(0050)
except AssertionError:
Expand Down