class YahooNews(): """get yahoo news""" industry_url = 'http://finance.yahoo.com/rss/industry?s=' headline_url = 'http://finance.yahoo.com/rss/headline?s=' blog_url = 'http://finance.yahoo.com/rss/blog?s=' def __init__(self): self.yql = YQLQuery() def getPublicNews(self,symbol,news_type,num_results): """Get Industry News from yahoo finance rss through YQL""" if news_type is "industry": url = self.industry_url + symbol elif news_type is "headline": url = self.headline_url + symbol if news_type is "blog": url = self.blog_url + symbol q = 'select * from rss where url = \'%s\'' % url ret = self.yql.execute(q) return ret['query']['results']['item'][:num_results]
def __init__(self): self.yql = YQLQuery()
def test_placeholder_regex_three(self): query = YQLQuery("SELECT * from foo where email=@foo and test=@bar'") placeholders = query.get_placeholder_keys() self.assertEqual(placeholders, ['foo', 'bar'])
def test_placeholder_regex_five(self): query = YQLQuery("""SELECT * from foo where foo='bar' LIMIT @foo""") placeholders = query.get_placeholder_keys() self.assertEqual(placeholders, ['foo'])
def test_requires_substitutions(self): query = YQLQuery("SELECT * from foo where dog=@dog") query.validate()
def test_placeholder_regex_one(self): query = YQLQuery("SELECT * from foo where email='*****@*****.**'") placeholders = query.get_placeholder_keys() self.assertEqual(placeholders, [])
def test_incorrect_type_raises_valueerror(self): query = YQLQuery("SELECT * from foo where dog=@test") params = ('fail') query.validate(params)
def test_unecessary_args_raises_valueerror(self): query = YQLQuery("SELECT * from foo where dog='test'") params = {'test': 'fail'} query.validate(params)
def test_params_raises_when_not_dict(self): query = YQLQuery("SELECT * from foo where dog=@dog") params = ['test'] query.validate(params)
def test_incorrect_args_raises_valueerror(self): query = YQLQuery("SELECT * from foo where dog=@dog") params = {'test': 'fail'} query.validate(params)
def test_empty_args_raises_valueerror(self): query = YQLQuery("SELECT * from foo where dog=@dog") params = {} query.validate(params)