Stream redmine updates to hipchat with python

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

Stream redmine updates to hipchat with python
Connect to BigQuery with Python
Connect to Wikipedia with Python
Switch python to 2.7 with alternatives
Write to csv with Python
Python: How to use async with
Link to get started with python
[Python] Write to csv file with Python
Create folders from '01' to '12' with python
Nice to meet you with python
Try to operate Facebook with Python
Output to csv file with Python
Stream videos to Chromecast with Gravio
MP3 to WAV conversion with Python
To do tail recursion with Python2
How to get started with Python
What to do with PYTHON release?
Unable to install Python with pyenv
How to use FTP with Python
How to calculate date with python
Notify HipChat with AWS Lambda (Python)
Easily post to twitter with Python 3
I want to debug with Python
I want to monitor UNIQLO + J page updates [Scraping with python]
Try to reproduce color film with Python
Try logging in to qiita with Python
Convert memo at once with Python 2to3
Memo to ask for KPI with python
Output color characters to pretty with python
Introduction to Python Image Inflating Image inflating with ImageDataGenerator
Output Python log to console with GAE
Convert Excel data to JSON with python
Convert Hiragana to Romaji with Python (Beta)
Fractal to make and play with Python
How to prevent package updates with apt
Connect to MySQL with Python within Docker
How to work with BigQuery in Python
[Introduction to Python] Let's use foreach with Python
Single pixel camera to experience with Python
[Python] Introduction to CNN with Pytorch MNIST
Convert FX 1-minute data to 5-minute data with Python
How to do portmanteau test with python
I want to play with aws with python
How to display python Japanese with lolipop
Trying to handle SQLite3 with Python [Note]
[Part1] Scraping with Python → Organize to csv!
How to enter Japanese with Python curses
Convert HEIC files to PNG files with Python
Convert Chinese numerals to Arabic numerals with Python
Connect to pepper with PEPPER Mac's python interpreter
To work with timestamp stations in Python
[Python] How to deal with module errors
I wanted to solve ABC172 with Python
Upload images to Google Drive with Python
The road to compiling to Python 3 with Thrift
How to install python3 with docker centos
Sample to convert image to Wavelet with Python
How to upload with Heroku, Flask, Python, Git (4)
[Python] Easy introduction to machine learning with python (SVM)
Introduction to Artificial Intelligence with Python 1 "Genetic Algorithm-Theory-"
How to read a CSV file with Python 2/3