From 050b730be81210affcd5cba5f8c306db5e4c7b14 Mon Sep 17 00:00:00 2001 From: Toomore Chiang Date: Wed, 1 Jan 2014 07:49:12 +0000 Subject: [PATCH 01/12] Add twse_no test into test_unittest. --- test_unittest.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test_unittest.py b/test_unittest.py index f451d6e..c43528d 100644 --- a/test_unittest.py +++ b/test_unittest.py @@ -44,5 +44,14 @@ def test_stock_value(self): assert isinstance(self.data.openprice, list) assert isinstance(self.data.value, list) + def test_twse_no(self): + twse_no = grs.TWSENo() + assert isinstance(twse_no.all_stock, dict) + result = twse_no.search(u'中') + # 1701 中化 + assert 1701 in result + result = twse_no.searchbyno(17) + assert 1701 in result + if __name__ == '__main__': unittest.main() From 2a0f194f6e787a708eafab8cd381d246469fefc0 Mon Sep 17 00:00:00 2001 From: Toomore Chiang Date: Wed, 1 Jan 2014 10:35:34 +0000 Subject: [PATCH 02/12] Remove testtwseno. --- .travis.yml | 1 - testtwseno.py | 20 -------------------- 2 files changed, 21 deletions(-) delete mode 100644 testtwseno.py diff --git a/.travis.yml b/.travis.yml index d426d1d..6532728 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,5 @@ install: python setup.py install script: - python grsTestAll.py - python testopen.py - - python testtwseno.py - python test_realtime.py - python test_unittest.py diff --git a/testtwseno.py b/testtwseno.py deleted file mode 100644 index 526eb3b..0000000 --- a/testtwseno.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -from grs import TWSENo - - -t = TWSENo() -print dir(t) - -t.all_stock # 所有股票代碼 type: dict - -''' IndCode -for i in t.IndComps: # 回傳類別所屬股票代碼 type: dict - print i,t.IndComps[i] -''' -print t.last_update -''' -'last_update', 'search', 'searchbyno' -''' -print t.search(u'中') # 搜尋股票名稱,回傳 type: dict -print t.searchbyno(23) # 搜尋股票名稱,回傳 type: dict From 8624abcd3d1741e6098f83874c89f0d737275d0a Mon Sep 17 00:00:00 2001 From: Toomore Chiang Date: Wed, 1 Jan 2014 11:03:55 +0000 Subject: [PATCH 03/12] Add twse open test into test_unittest. --- .travis.yml | 1 - test_unittest.py | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6532728..992c86a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,5 @@ python: install: python setup.py install script: - python grsTestAll.py - - python testopen.py - python test_realtime.py - python test_unittest.py diff --git a/test_unittest.py b/test_unittest.py index c43528d..cf08d83 100644 --- a/test_unittest.py +++ b/test_unittest.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- ''' Unittest ''' +from datetime import datetime from types import BooleanType from types import NoneType import grs @@ -53,5 +54,10 @@ def test_twse_no(self): result = twse_no.searchbyno(17) assert 1701 in result + def test_twse_open(self): + is_open = grs.TWSEOpen() + result = is_open.d_day(datetime(2014, 1, 1)) + assert result is False + if __name__ == '__main__': unittest.main() From 207aa0fabc470898db8f5e2cc1063307fe1cbe5e Mon Sep 17 00:00:00 2001 From: Toomore Chiang Date: Wed, 1 Jan 2014 11:09:27 +0000 Subject: [PATCH 04/12] Remove no use test. --- .travis.yml | 1 - grsTestAll.py | 6 ------ test2.py | 32 -------------------------------- testB4P.py | 15 --------------- test_prof.py | 17 ----------------- testopen.py | 9 --------- 6 files changed, 80 deletions(-) delete mode 100644 grsTestAll.py delete mode 100644 test2.py delete mode 100644 testB4P.py delete mode 100644 test_prof.py delete mode 100644 testopen.py diff --git a/.travis.yml b/.travis.yml index 992c86a..dc7e117 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,5 @@ python: - pypy install: python setup.py install script: - - python grsTestAll.py - python test_realtime.py - python test_unittest.py diff --git a/grsTestAll.py b/grsTestAll.py deleted file mode 100644 index c3f1f8c..0000000 --- a/grsTestAll.py +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -import grs - -for i in dir(grs): - print getattr(grs,i) diff --git a/test2.py b/test2.py deleted file mode 100644 index 1e72427..0000000 --- a/test2.py +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -from grs import stock - - -a = stock(2618) -''' -print 'Row Data' -print a.row_data -print '=' * 20 -print 'Row 6 Data' -print a.serial_price(6) -print '=' * 20 -''' -print 'MA3' -print '=' * 20 -print a.MA(3) -print a.MAV(3) -print '' -print 'MA6' -print '=' * 20 -print a.MA(6) -print a.MAV(6) -print '' -print 'MA18' -print '=' * 20 -print a.MA(18) -print a.MAV(18) -print '' -print 'VAL' -print '=' * 20 -print a.MAV(1) diff --git a/testB4P.py b/testB4P.py deleted file mode 100644 index 78acaf5..0000000 --- a/testB4P.py +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -from grs import B4P, stock, twseno - -l = twseno().AllStockNo - -for i in l: - try: - BS, info = B4P(stock(i)).B4Point() - if BS: # 買點 - print 'B: {0} {1}'.format(i, info) - else: # 賣點 - print 'S: {0} {1}'.format(i, info) - except: # 不作為或資料不足 - print 'X: {0}'.format(i) diff --git a/test_prof.py b/test_prof.py deleted file mode 100644 index d172769..0000000 --- a/test_prof.py +++ /dev/null @@ -1,17 +0,0 @@ -from time import time -from datetime import datetime -from grs import stock -t = time() -a = [] -times = 1 - -for i in range(times): - tt = time() - stock(1201).MA(3) - a.append(time()-tt) - -print "end {0}".format(datetime.now()) -print "Max: {0}".format(max(a)) -print "Min: {0}".format(min(a)) -print "ALL: {0}".format(time()-t) -print "Avg: {0}".format((sum(a)-max(a)-min(a))/(times-2)) diff --git a/testopen.py b/testopen.py deleted file mode 100644 index 9685101..0000000 --- a/testopen.py +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -from datetime import datetime -from grs import TWSEOpen - -t = TWSEOpen() - -print t.d_day(datetime.today()) -print t.d_day(datetime(2014, 1, 1)) From 5b655923f3ef322c0e5194c591dba331c89a6b4e Mon Sep 17 00:00:00 2001 From: Toomore Chiang Date: Wed, 1 Jan 2014 15:23:06 +0000 Subject: [PATCH 05/12] Add real_time test into test_unittest and fixed #4 --- .travis.yml | 1 - test_realtime.py | 19 ------------------- test_unittest.py | 6 ++++++ 3 files changed, 6 insertions(+), 20 deletions(-) delete mode 100644 test_realtime.py diff --git a/.travis.yml b/.travis.yml index dc7e117..78ef550 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,5 +5,4 @@ python: - pypy install: python setup.py install script: - - python test_realtime.py - python test_unittest.py diff --git a/test_realtime.py b/test_realtime.py deleted file mode 100644 index 46301c6..0000000 --- a/test_realtime.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -from grs import RealtimeStock -from grs import RealtimeWeight - - -r = RealtimeStock(2618) -print 'real' -print '=' * 20 -#for i in r.real: - #print i, r.real[i] -print r.real -print 'raw' -print '=' * 20 -print r.raw -rw = RealtimeWeight() -print 'weight' -print '=' * 20 -print rw.real diff --git a/test_unittest.py b/test_unittest.py index cf08d83..723edd9 100644 --- a/test_unittest.py +++ b/test_unittest.py @@ -59,5 +59,11 @@ def test_twse_open(self): result = is_open.d_day(datetime(2014, 1, 1)) assert result is False + def test_realtime(self): + real_time = grs.RealtimeStock(self.stock_no) + assert real_time.real['no'] == self.stock_no + real_time = grs.RealtimeWeight() + assert real_time.real['no'] == '1' + if __name__ == '__main__': unittest.main() From 0103cd4efbddae98a19f9e87367117b6bea6af17 Mon Sep 17 00:00:00 2001 From: Toomore Chiang Date: Wed, 1 Jan 2014 15:38:12 +0000 Subject: [PATCH 06/12] Remove support Python 2.6 --- .travis.yml | 1 - README.rst | 2 +- setup.py | 1 - test_unittest.py | 2 +- 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 78ef550..040cdf4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: python python: - - 2.6 - 2.7 - pypy install: python setup.py install diff --git a/README.rst b/README.rst index 093ddbc..38c666e 100644 --- a/README.rst +++ b/README.rst @@ -25,7 +25,7 @@ grs 台灣上市股票價格擷取 :Authors: Toomore Chiang :Version: 0.4.0 of 2013/12/30 -:Python Version: Python 2.6-2.7, PyPy +:Python Version: Python 2.7, PyPy ----------------------------- Requires diff --git a/setup.py b/setup.py index 06ff53e..c20edd2 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,6 @@ 'License :: OSI Approved :: MIT License', 'Natural Language :: Chinese (Traditional)', 'Programming Language :: Python', - 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Topic :: Office/Business :: Financial :: Investment', ], diff --git a/test_unittest.py b/test_unittest.py index 723edd9..fa3f4d6 100644 --- a/test_unittest.py +++ b/test_unittest.py @@ -61,7 +61,7 @@ def test_twse_open(self): def test_realtime(self): real_time = grs.RealtimeStock(self.stock_no) - assert real_time.real['no'] == self.stock_no + assert real_time.real['no'] == self.stock_no real_time = grs.RealtimeWeight() assert real_time.real['no'] == '1' From 001431b3c13a09da53a4442fa27ce8c3a4c4da73 Mon Sep 17 00:00:00 2001 From: Toomore Chiang Date: Wed, 1 Jan 2014 15:50:17 +0000 Subject: [PATCH 07/12] Fixed grs.Countdown self.__zero should be a function. --- grs/tw_time.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/grs/tw_time.py b/grs/tw_time.py index e11bcd5..0df3159 100644 --- a/grs/tw_time.py +++ b/grs/tw_time.py @@ -68,10 +68,14 @@ class Countdown(object): ''' def __init__(self, hour=14, minutes=30): self.__back = timedelta(hours=hour - 8, minutes=minutes) - self.__zero = datetime.utcnow() - self.__back self.__hour = hour self.__minutes = minutes + @property + def __zero(self): + ''' 取得現在時間(秒) ''' + return datetime.utcnow() - self.__back + @property def nextday(self): ''' nextday: 下一個日期 ''' From 4163ff9cca4f17c9ed4877af21ba2aab9804ef98 Mon Sep 17 00:00:00 2001 From: Toomore Chiang Date: Wed, 1 Jan 2014 15:56:19 +0000 Subject: [PATCH 08/12] Tiny changed in test_unittest. --- test_unittest.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test_unittest.py b/test_unittest.py index fa3f4d6..8a98d19 100644 --- a/test_unittest.py +++ b/test_unittest.py @@ -8,39 +8,46 @@ class TestGrs(unittest.TestCase): - def setUp(self): + def get_data(self): self.stock_no = '2618' self.data = grs.Stock(self.stock_no) def test_stock(self): + self.get_data() assert self.data.info[0] == self.stock_no def test_best_buy_or_sell(self): + self.get_data() assert isinstance(grs.BestFourPoint(self.data).best_four_point(), (tuple, NoneType)) def test_moving_average(self): + self.get_data() result = self.data.moving_average(3) assert isinstance(result[0], list) assert isinstance(result[1], int) def test_moving_average_value(self): + self.get_data() result = self.data.moving_average_value(3) assert isinstance(result[0], list) assert isinstance(result[1], int) def test_moving_average_bias_ratio(self): + self.get_data() result = self.data.moving_average_bias_ratio(6, 3) assert isinstance(result[0], list) assert isinstance(result[1], int) def test_check_moving_average_bias_ratio(self): + self.get_data() result = self.data.check_moving_average_bias_ratio( self.data.moving_average_bias_ratio(3, 6)[0], positive_or_negative=True)[0] assert isinstance(result, BooleanType) def test_stock_value(self): + self.get_data() assert isinstance(self.data.price, list) assert isinstance(self.data.openprice, list) assert isinstance(self.data.value, list) @@ -60,8 +67,8 @@ def test_twse_open(self): assert result is False def test_realtime(self): - real_time = grs.RealtimeStock(self.stock_no) - assert real_time.real['no'] == self.stock_no + real_time = grs.RealtimeStock('2618') + assert real_time.real['no'] == '2618' real_time = grs.RealtimeWeight() assert real_time.real['no'] == '1' From f58484bdcc1407904d40f7f569195f3d98dd6a16 Mon Sep 17 00:00:00 2001 From: Toomore Chiang Date: Wed, 1 Jan 2014 16:24:45 +0000 Subject: [PATCH 09/12] Add Countdown test into test_unittest. --- test_unittest.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test_unittest.py b/test_unittest.py index 8a98d19..066969a 100644 --- a/test_unittest.py +++ b/test_unittest.py @@ -72,5 +72,10 @@ def test_realtime(self): real_time = grs.RealtimeWeight() assert real_time.real['no'] == '1' + @staticmethod + def test_countdown(): + result = grs.Countdown().countdown + assert isinstance(result, int) + if __name__ == '__main__': unittest.main() From f15464ede7e87089d58315b971a962c48fafa7a7 Mon Sep 17 00:00:00 2001 From: Toomore Chiang Date: Wed, 1 Jan 2014 16:35:23 +0000 Subject: [PATCH 10/12] Some test using staticmethod. #4 --- test_unittest.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test_unittest.py b/test_unittest.py index 066969a..331ed97 100644 --- a/test_unittest.py +++ b/test_unittest.py @@ -52,7 +52,8 @@ def test_stock_value(self): assert isinstance(self.data.openprice, list) assert isinstance(self.data.value, list) - def test_twse_no(self): + @staticmethod + def test_twse_no(): twse_no = grs.TWSENo() assert isinstance(twse_no.all_stock, dict) result = twse_no.search(u'中') @@ -61,12 +62,14 @@ def test_twse_no(self): result = twse_no.searchbyno(17) assert 1701 in result - def test_twse_open(self): + @staticmethod + def test_twse_open(): is_open = grs.TWSEOpen() result = is_open.d_day(datetime(2014, 1, 1)) assert result is False - def test_realtime(self): + @staticmethod + def test_realtime(): real_time = grs.RealtimeStock('2618') assert real_time.real['no'] == '2618' real_time = grs.RealtimeWeight() From 228babe3c420514d222a439b3c01d823b7e3dc8a Mon Sep 17 00:00:00 2001 From: Toomore Chiang Date: Wed, 1 Jan 2014 16:45:16 +0000 Subject: [PATCH 11/12] Tiny changed in README. --- README.rst | 9 ++++++++- grs/__init__.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 38c666e..92fdda8 100644 --- a/README.rst +++ b/README.rst @@ -24,7 +24,7 @@ grs 台灣上市股票價格擷取 ----------------------------- :Authors: Toomore Chiang -:Version: 0.4.0 of 2013/12/30 +:Version: 0.4.1 of 2014/01/02 :Python Version: Python 2.7, PyPy ----------------------------- @@ -277,6 +277,13 @@ Quick Start Change Logs ----------------------------- +0.4.1 2014/01/02 +==================================== + +- 修正:Countdown().countdown 秒數問題 +- 新增:twse_no, twse_open, twse_realtime, countdown into unittest +- 移除:Support Python 2.6 + 0.4.0 2013/12/30 ==================================== diff --git a/grs/__init__.py b/grs/__init__.py index 7351bb6..ebf458e 100644 --- a/grs/__init__.py +++ b/grs/__init__.py @@ -21,7 +21,7 @@ # THE SOFTWARE. __title__ = 'grs' -__version__ = '0.4.0' +__version__ = '0.4.1' __author__ = 'Toomore Chiang' __license__ = 'MIT' __copyright__ = 'Copyright (C) 2012, 2013, 2014 Toomore Chiang' From c904146435064f668685aee78f58a50d086b602a Mon Sep 17 00:00:00 2001 From: Toomore Chiang Date: Wed, 1 Jan 2014 16:48:32 +0000 Subject: [PATCH 12/12] Add dist files into gitignore. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 626b9ae..d51e7e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ *.pyc *.pylint +build/ +dist/ +grs.egg-info/