In IRC, I send an update of redmine to ikachan and notify it, but I wanted to send it to hipchat as well, so I wrote a script in python after a long time. The library that hits HipChat's API is officially organized. python is on PyPI, so you can install it with pip install python-hipchat.
I think you can throw anything that can be parsed by RSS.
# -*- 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()
I thought it took me a while to find the equivalent of Cache :: FileCache in Perl, and I forgot to write python after a long time.
Recommended Posts