Skip to content

Commit

Permalink
Update realtime bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mlouielu committed Mar 22, 2018
1 parent fbc780d commit 62ebad5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion test/test_realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ def test_realtime_field(self):
twstock.mock.get_stock_info('2330').keys())

def test_realtime_get_raw(self):
self.assertIn('msgArray', realtime.get_raw('2330'))
retry = 5
for _ in range(retry):
stock = realtime.get_raw('2330')
if stock['rtcode'] == '0000' and stock['rtmessage'] != 'OK':
continue
self.assertIn('msgArray', realtime.get_raw('2330'))
break

def test_realtime_get_blank(self):
stock = realtime.get('')
Expand Down
4 changes: 2 additions & 2 deletions twstock/realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ def get_raw(stocks) -> dict:
return {'rtmessage': 'json decode error', 'rtcode': '5000'}


def get(stocks, retry=3):
def get(stocks, retry=10):
# Prepare data
data = get_raw(stocks) if not mock else twstock.mock.get(stocks)

# Set success
data['success'] = False

# JSONdecode error, could be too fast, retry
if data['rtcode'] == '5000':
if data['rtcode'] == '0000':
# XXX: Stupit retry, you will dead here
if retry:
return get(stocks, retry - 1)
Expand Down

0 comments on commit 62ebad5

Please sign in to comment.