From 6225cecf45a62a9cc97976fca982fe13b91c0460 Mon Sep 17 00:00:00 2001 From: Austin Maliszewski Date: Wed, 26 May 2021 10:31:29 -0500 Subject: [PATCH] Fix issue with historical quotes for mutual funds Mutual funds do not have volume information, so int parse was failing. Also fixed warning about 'is' comparison with literal. --- stockquotes/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stockquotes/__init__.py b/stockquotes/__init__.py index c1d76ce..1df35b8 100644 --- a/stockquotes/__init__.py +++ b/stockquotes/__init__.py @@ -48,7 +48,7 @@ class Stock: ) except: raise NetworkError() - if r.status_code is 302: + if r.status_code == 302: raise StockDoesNotExistError(ticker) try: soup = bs(r.text, features="lxml") @@ -70,7 +70,9 @@ class Stock: "adjusted_close": float( row[5].span.string.replace(",", "") ), - "volume": int(row[6].span.string.replace(",", "")), + "volume": int(row[6].span.string.replace(",", "")) + if row[6].string != "-" + else None, } except: continue