Created
February 1, 2014 13:39
-
-
Save vkgtaro/8752497 to your computer and use it in GitHub Desktop.
python で redmine の更新を hipchat へ流す ref: http://qiita.com/vkgtaro/items/dc776a6b907cafed57ff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| from datetime import datetime | |
| from fcache.cache import FileCache | |
| import feedparser | |
| from hypchat import HypChat | |
| import hashlib | |
| import os | |
| import pytz | |
| import time | |
| os.environ['TZ'] = 'UTC' | |
| room_id = 123456 | |
| feed_url = "http://redmine/issue/atom/url" | |
| feed = feedparser.parse(feed_url) | |
| cache_key = hashlib.sha224(feed_url).hexdigest() | |
| cache = FileCache('/tmp/redmine') | |
| hc = HypChat("YOUR API TOKEN") | |
| tz_utc = pytz.timezone('UTC') | |
| if not cache.get(cache_key): | |
| cache[cache_key] = time.mktime(datetime.now(tz_utc).timetuple()) | |
| last_updated = cache[cache_key] | |
| for entry in feed['entries']: | |
| updated = time.mktime(datetime.strptime(entry.updated, '%Y-%m-%dT%H:%M:%SZ').timetuple()) | |
| if int( last_updated ) >= int( updated ): | |
| print "continue: %s > %s" % (cache[cache_key], updated) | |
| continue | |
| if cache[cache_key] <= updated: | |
| cache[cache_key] = updated | |
| if entry.authors[0].name: | |
| name = entry.authors[0].name | |
| message = '<a href="%s">%s</a> (%s)' % (entry.link, entry.title, name) | |
| hc.get_room(room_id).notification(message, color='gray') | |
| cache.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment