From 38fcb4316436aa964b5a2c8180449daa62c90401 Mon Sep 17 00:00:00 2001 From: Toomore Chiang Date: Fri, 10 Jan 2014 20:18:16 +0800 Subject: [PATCH 1/7] Add assert for `stock_no`. #9 --- grs/fetch_data.py | 1 + 1 file changed, 1 insertion(+) diff --git a/grs/fetch_data.py b/grs/fetch_data.py index 66ce93b..e8455f1 100644 --- a/grs/fetch_data.py +++ b/grs/fetch_data.py @@ -35,6 +35,7 @@ def __init__(self, stock_no, mons=3): :stock_no : 股價代碼 :mons : 擷取近 n 個月的資料 """ + assert isinstance(stock_no, str), '`stock_no` must be a string' self.__get_mons = 0 self.__get_no = 0 self.__info = () From cc4e644312cdf27b48dcff3ca8941e77638d508b Mon Sep 17 00:00:00 2001 From: Toomore Chiang Date: Fri, 10 Jan 2014 20:24:49 +0800 Subject: [PATCH 2/7] Add some test for '0050'. #9 --- test_unittest.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test_unittest.py b/test_unittest.py index 331ed97..fbbf1c1 100644 --- a/test_unittest.py +++ b/test_unittest.py @@ -80,5 +80,14 @@ def test_countdown(): result = grs.Countdown().countdown assert isinstance(result, int) + @staticmethod + def test_taiwan_50(): + stock = grs.Stock('0050') + assert u'台灣50' == stock.info[1] + try: + stock = grs.Stock(0050) + except AssertionError: + pass + if __name__ == '__main__': unittest.main() From eccd55dd6b971c1a488e351072a429045152a48a Mon Sep 17 00:00:00 2001 From: Toomore Chiang Date: Fri, 10 Jan 2014 20:30:18 +0800 Subject: [PATCH 3/7] Add assert into realtime. #9 --- grs/realtime.py | 1 + 1 file changed, 1 insertion(+) diff --git a/grs/realtime.py b/grs/realtime.py index 85cc0fe..2615bcf 100644 --- a/grs/realtime.py +++ b/grs/realtime.py @@ -61,6 +61,7 @@ class RealtimeStock(object): crosspic: K線圖 by Google Chart """ def __init__(self, no): + assert isinstance(no, str), '`no` must be a string' self.__raw = '' page = urllib2.urlopen( 'http://mis.tse.com.tw/data/{0}.csv?r={1}'.format( From bb36eea9e2f451d8cb6413c4edf3fe92cb9cad54 Mon Sep 17 00:00:00 2001 From: Toomore Chiang Date: Fri, 10 Jan 2014 21:07:29 +0800 Subject: [PATCH 4/7] Add test for realtime. #9 --- test_unittest.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test_unittest.py b/test_unittest.py index fbbf1c1..5ede608 100644 --- a/test_unittest.py +++ b/test_unittest.py @@ -74,6 +74,12 @@ def test_realtime(): assert real_time.real['no'] == '2618' real_time = grs.RealtimeWeight() assert real_time.real['no'] == '1' + real_time = grs.RealtimeStock('0050') + assert real_time.real['no'] == '0050' + try: + real_time = grs.RealtimeStock(0050) + except AssertionError: + pass @staticmethod def test_countdown(): From 7f5294957ce699e611c8f2a09a5f5eb8d79a9344 Mon Sep 17 00:00:00 2001 From: Toomore Chiang Date: Fri, 10 Jan 2014 21:31:01 +0800 Subject: [PATCH 5/7] Add change log. --- README.rst | 9 ++++++++- grs/__init__.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 92fdda8..8ec046c 100644 --- a/README.rst +++ b/README.rst @@ -24,7 +24,7 @@ grs 台灣上市股票價格擷取 ----------------------------- :Authors: Toomore Chiang -:Version: 0.4.1 of 2014/01/02 +:Version: 0.4.2 of 2014/01/11 :Python Version: Python 2.7, PyPy ----------------------------- @@ -277,6 +277,13 @@ Quick Start Change Logs ----------------------------- + +0.4.2 2014/01/11 +==================================== + +- 修正:Stock 參數 `stock_no`, RealtimeStock 參數 `no` 必須為 string. + `Issues #9 `_ + 0.4.1 2014/01/02 ==================================== diff --git a/grs/__init__.py b/grs/__init__.py index ebf458e..1b7622d 100644 --- a/grs/__init__.py +++ b/grs/__init__.py @@ -21,7 +21,7 @@ # THE SOFTWARE. __title__ = 'grs' -__version__ = '0.4.1' +__version__ = '0.4.2' __author__ = 'Toomore Chiang' __license__ = 'MIT' __copyright__ = 'Copyright (C) 2012, 2013, 2014 Toomore Chiang' From b3bf79941de8ccf33842fde723229dcfb3fc0d47 Mon Sep 17 00:00:00 2001 From: Toomore Chiang Date: Fri, 10 Jan 2014 21:33:28 +0800 Subject: [PATCH 6/7] Update ./README.rst example. --- README.rst | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.rst b/README.rst index 8ec046c..0973721 100644 --- a/README.rst +++ b/README.rst @@ -56,7 +56,7 @@ Quick Start from grs import Stock - stock = Stock(2618) # 擷取長榮航股價 + stock = Stock('2618') # 擷取長榮航股價 print stock.moving_average(5) # 計算五日均價與持續天數 print stock.moving_average_value(5) # 計算五日均量與持續天數 print stock.moving_average_bias_ratio(5,10) # 計算五日、十日乖離值與持續天數 @@ -66,7 +66,7 @@ Quick Start :: - stock = Stock(2618, 12) + stock = Stock('2618', 12) 輸出 CSV 檔 @@ -89,8 +89,8 @@ Quick Start from grs import TWTime what_time = TWTime() - what_time.now() # 顯示台灣此刻時間 - what_time.localtime() # 顯示當地此刻時間 + what_time.now() # 顯示台灣此刻時間 + what_time.localtime() # 顯示當地此刻時間 判斷台灣股市是否開市:TWSEOpen @@ -115,9 +115,9 @@ Quick Start from grs import RealtimeStock - realtime_stock = RealtimeStock(2618) # 擷取長榮航即時股價 - realtime_stock.raw # 原始資料 - realtime_stock.real # 回傳 type: dict(如下表) + realtime_stock = RealtimeStock('2618') # 擷取長榮航即時股價 + realtime_stock.raw # 原始資料 + realtime_stock.real # 回傳 type: dict(如下表) :name: 股票名稱 Unicode @@ -209,7 +209,7 @@ Quick Start from grs import Stock - stock = Stock(2618) + stock = Stock('2618') data = stock.moving_average_bias_ratio(3,6)[0] # 取得 3-6 乖離值 type: list # 計算五個區間負乖離轉折點 @@ -228,7 +228,7 @@ Quick Start from grs import BestFourPoint from grs import Stock - stock = Stock(2618) + stock = Stock('2618') result = BestFourPoint(stock) result.best_four_point_to_buy() # 判斷是否為四大買點 result.best_four_point_to_sell() # 判斷是否為四大賣點 @@ -264,7 +264,7 @@ Quick Start from grs import Stock - stock = Stock(2618) # 預設為抓取3個月份資料 + stock = Stock('2618') # 預設為抓取3個月份資料 stock.moving_average(60) IndexError: list index out of range # 資料不足 len(stock.raw) # 回傳 51 個值 From 3ddfcf29924e4de104c7374d345f8ebffdc05e5e Mon Sep 17 00:00:00 2001 From: Toomore Chiang Date: Fri, 10 Jan 2014 21:41:27 +0800 Subject: [PATCH 7/7] Tiny changed in README. --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 0973721..c745652 100644 --- a/README.rst +++ b/README.rst @@ -281,7 +281,7 @@ Change Logs 0.4.2 2014/01/11 ==================================== -- 修正:Stock 參數 `stock_no`, RealtimeStock 參數 `no` 必須為 string. +- 修正:Stock ``stock_no``, RealtimeStock ``no`` 必須為 *string*. `Issues #9 `_ 0.4.1 2014/01/02