def setUp(self,): self.stock = StockRetriever(format='json')
class TestStockScraper(unittest.TestCase): def setUp(self,): self.stock = StockRetriever(format='json') def tearDown(self): pass def test_get_current_info(self,): data = self.stock.get_current_info(["YHOO","AAPL","GOOG","J&KBANK.BO"]) logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200) def test_get_current_info_with_one_symbol(self,): data = self.stock.get_current_info(["J&KBANK.BO"]) logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200) def test_get_news_feed(self,): data = self.stock.get_news_feed('YHOO') logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200) def test_get_historical_info_with_args(self,): data = self.stock.get_historical_info('YHOO',items=['Open','Close','High','Low'], limit=5,startDate='2014-09-11',endDate='2015-02-10') logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200) def test_get_historical_info_without_args(self,): data = self.stock.get_historical_info('YHOO') logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200) def test_get_options_info(self,): data = self.stock.get_options_info('YHOO') logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200) def test_get_index_summary(self,): data = self.stock.get_index_summary('GOOG',('Volume','Change')) logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200) def test_get_industry_index(self,): data = self.stock.get_industry_index(112) #logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200) def test_get_symbols(self,): data = self.stock.get_symbols('Google') logging.debug(pretty_json(data.content)) self.assertIn(data.status_code, (200, 400, "Web Service is currently Down!!")) def test_get_xchange_rate(self,): data = self.stock.get_xchange_rate(['EURUSD','GBPUSD']) logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200) def test_get_dividendhistory(self,): data = self.stock.get_dividendhistory('AAPL',"2008-01-01", "2015-06-15") logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200) def test_get_balancesheet(self,): data = self.stock.get_balancesheet('YHOO') logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200)
#!/usr/bin/python3 from myql.contrib.finance.stockscraper import StockRetriever stocks = StockRetriever(format='json') info = ['Symbol','Date','Close','Open','High','Low','Volume'] data = stocks.get_historical_info("YHOO",items=info, limit=5,startDate='2016-01-01',endDate='2016-01-16').json() print("\n\n") # print(data) for r in data['query']['results']['quote']: print( r ) if False: for n in data: # print(n.Bid) print('.')
def setUp(self, ): self.stock = StockRetriever(format='json')
class TestStockScraper(unittest.TestCase): def setUp(self, ): self.stock = StockRetriever(format='json') def tearDown(self): pass def test_get_current_info(self, ): data = self.stock.get_current_info( ["YHOO", "AAPL", "GOOG", "J&KBANK.BO"]) logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200) def test_get_current_info_with_one_symbol(self, ): data = self.stock.get_current_info(["J&KBANK.BO"]) logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200) def test_get_news_feed(self, ): data = self.stock.get_news_feed('YHOO') logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200) def test_get_historical_info_with_args(self, ): data = self.stock.get_historical_info( 'YHOO', items=['Open', 'Close', 'High', 'Low'], limit=5, startDate='2014-09-11', endDate='2015-02-10') logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200) def test_get_historical_info_without_args(self, ): data = self.stock.get_historical_info('YHOO') logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200) def test_get_options_info(self, ): data = self.stock.get_options_info('YHOO') logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200) def test_get_index_summary(self, ): data = self.stock.get_index_summary('GOOG', ('Volume', 'Change')) logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200) def test_get_industry_index(self, ): data = self.stock.get_industry_index(112) #logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200) def test_get_symbols(self, ): data = self.stock.get_symbols('Google') logging.debug(pretty_json(data.content)) self.assertIn(data.status_code, (200, 400, "Web Service is currently Down!!")) def test_get_xchange_rate(self, ): data = self.stock.get_xchange_rate(['EURUSD', 'GBPUSD']) logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200) def test_get_dividendhistory(self, ): data = self.stock.get_dividendhistory('AAPL', "2008-01-01", "2015-06-15") logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200) def test_get_balancesheet(self, ): data = self.stock.get_balancesheet('YHOO') logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200)
#!/usr/bin/python3 from myql.contrib.finance.stockscraper import StockRetriever stocks = StockRetriever(format='json') data = stocks.get_current_info(["YHOO","AAPL","GOOG"]).json() print("\n\n") print(type(data)) for n in data['query']['results']['quote']: print( n['symbol'],end=' ' ) print( n['Bid'] ,end=' ') print( n['Ask'] ,end=' ') print( n['Volume'] ,end=' ') print( n['LastTradeDate'] ,end=' ') print( n['LastTradeTime'] ,end=' ') print( n['LastTradePriceOnly'] )