diff --git a/README.rst b/README.rst index 53cf889..6495f18 100644 --- a/README.rst +++ b/README.rst @@ -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)股價資料 @@ -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/ @@ -286,6 +286,11 @@ Quick Start Change Logs ----------------------------- +0.7.0 2016/09/11 +==================================== + +- 修正:上市(TWSE)擷取連結 + 0.6.2 2015/03/20 ==================================== diff --git a/docs/source/index.rst b/docs/source/index.rst index ac00d51..87b3906 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -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)股價資料 @@ -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/ @@ -83,6 +83,9 @@ Feature Change Logs ----------------------------- +* 0.7.0 2016/09/11 + - 修正:上市(TWSE)擷取連結 + * 0.6.2 2015/03/20 - 修正:上櫃(OTC)擷取連結 @@ -164,4 +167,3 @@ Indices and tables * :ref:`genindex` * :ref:`modindex` * :ref:`search` - diff --git a/grs/__init__.py b/grs/__init__.py index b184f3d..a941a8d 100644 --- a/grs/__init__.py +++ b/grs/__init__.py @@ -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 diff --git a/grs/fetch_data.py b/grs/fetch_data.py index c468fc2..f21a81d 100644 --- a/grs/fetch_data.py +++ b/grs/fetch_data.py @@ -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([]) @@ -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 @@ -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): """ 成交量序列(張) diff --git a/test_unittest.py b/test_unittest.py index ca6a411..7179e22 100644 --- a/test_unittest.py +++ b/test_unittest.py @@ -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: