def test_get_all(self): url = "https://news.yahoo.com/rss/" lim = 3 hand = Handler(url, lim) self.assertIsInstance(hand.get_all(), list) self.assertIsInstance(hand.get_all()[0], News) self.assertEqual(len(hand.get_all()), lim)
def main(): arg = get_console_argument() link = arg.link lim = -1 if arg.version: print("version: 4.0") if arg.verbose: logging.getLogger().setLevel(logging.INFO) # if user enter to_html if arg.to_html: # if user enter link if arg.link: if arg.limit: if arg.limit <= 0: raise RssException("Error count news <=0") lim = arg.limit hand = Handler(link, lim) news = hand.get_all() # if user enter --date elif arg.date: if arg.limit: lim = arg.limit dict_news = read_from_file(arg.date, lim) news = convert_Dict_to_News(dict_news) else: raise RssException("Error. Please enter url or --date") create_html_news(arg.to_html, news) # if user enter to_pdf elif arg.to_pdf: # if user enter link if arg.link: if arg.limit: if arg.limit <= 0: raise RssException("Error count news <=0") lim = arg.limit hand = Handler(link, lim) news = hand.get_all() # if user --date elif arg.date: if arg.limit: lim = arg.limit dict_news = read_from_file(arg.date, lim) news = convert_Dict_to_News(dict_news) else: raise RssException("Error. Please enter url or --date") create_pdf_news(arg.to_pdf, news) elif arg.date: if arg.limit: lim = arg.limit news = read_from_file(arg.date, lim) if arg.json: print_json(news) else: print_array_of_dict(news) else: # standart value -1, in handler we will process and get all the value if arg.limit or arg.limit == 0: if arg.limit <= 0: raise RssException("Error count news <=0") lim = arg.limit hand = Handler(link, lim) news = hand.get_all() if len(news) < lim: raise RssException("not have this count of news") if arg.json: arr_json = [] for i in news: arr_json.append(parse_to_json(i)) print_json(arr_json) else: print_array_of_news(news)