class TmNCTReporterTest(unittest.TestCase): def setUp(self): self.reporter = TmNCTReporter(settings_test.FEED_URL, settings_test.CACHE_PATH, settings_test.DEBUG) def test_get_latest_news(self): news = self.reporter.get_latest_news() print u""" latest_news info titile: {0} link: {1} published: {2}""".format( self.reporter.latest_news[0], self.reporter.latest_news[1], self.reporter.latest_news[2] ) self.assertTrue(news) def test_is_updated_news(self): self.reporter.latest_news = self.reporter.get_latest_news() self.reporter.is_updated_news() print u""" local_data info title: {0} link: {1} published: {2}""".format( self.reporter.local_data[0], self.reporter.local_data[1], self.reporter.local_data[2] ) def test_save_latest_news(self): self.reporter.latest_news = self.reporter.get_latest_news() self.reporter.save_latest_news()
#!/usr/bin/env python # coding:utf-8 from datetime import datetime from modules.tmnctreporter import TmNCTReporter from modules.tweetman import TweetMan import settings if __name__ == '__main__': try: logger = open('./reportlog.log', 'a') except IOError: pass logger.write(u"Start TmNCT_News at {0}\n".format(datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S"))) reporter = TmNCTReporter(settings.FEED_URL, settings.CACHE_PATH) if reporter.is_updated_news(): logger.write(u"Updated!!\n") reporter.save_latest_news() tweetman = TweetMan(settings.CONSUMER_KEY, settings.CONSUMER_SECRET, settings.ACCESS_TOKEN, settings.ACCESS_TOKEN_SECRET) tweet = u"{0}\n{1} #苫小牧高専".format(reporter.latest_news[0], reporter.latest_news[1]) if not tweetman.send_tweet(tweet) is False: logger.write(u"completed send_tweet!\n") else: logger.write(u"send_tweet missing...\n") else: logger.write('Not Updated...\n')
def setUp(self): self.reporter = TmNCTReporter(settings_test.FEED_URL, settings_test.CACHE_PATH, settings_test.DEBUG)