コード例 #1
0
import settings

if __name__ == '__main__':
    try:
        logger = open('./weatherlog.log', 'a')
    except IOError:
        pass

    logger.write(u"Start WeatherForecaster at {0}\n".format(datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d %H:%M:%S")))

    reporter = WeatherForecaster(settings.WEATHER_XML_URL, settings.WEATHER_AREA_NAME)
    today_weather = reporter.get_today_weather()
    today_max_temperature = reporter.get_today_max_temperature()
    today_min_temperature = reporter.get_today_min_temperature()

    tweetman = TweetMan(settings.CONSUMER_KEY, settings.CONSUMER_SECRET,
            settings.ACCESS_TOKEN, settings.ACCESS_TOKEN_SECRET)
    tweet = u"""{today}の{area}
    天気:{weather},
    最高気温:{max_temp}℃,
    最低気温:{min_temp}℃""".format(today = unicode(datetime.date.today()).replace('-', '/'),
            area = settings.WEATHER_AREA_NAME, weather = today_weather,
            max_temp = today_max_temperature, min_temp = today_min_temperature)

    if tweetman.send_tweet(tweet) is not False:
        logger.write(u"conpleted send_tweet!\n")
    else:
        logger.write(u"send_tweet missing...\n")

    logger.write(u"End.\n\n")
    logger.close()
コード例 #2
0
ファイル: main.py プロジェクト: TmNCT-Josho/TmNCT_News
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')

    logger.write(u"End.\n\n")
    logger.close()