Friendfeed のエントリを Growl で表示
Friendfeed API を python から使い新規更新分のエントリを Growl に表示するスクリプトを作ったので公開。
friendfeed-api
http://code.google.com/p/friendfeed-api/
からライブラリを落としてきて python ディレクトリの friendfeed.py を使用。
自分の feed を取るのに remote key が必要なので、friendfeed にログインしたまま
https://friendfeed.com/account/api
にアクセスして入手。
python から Growl を使う方法はid:nishiohirokazuの[http://d.hatena.ne.jp/nishiohirokazu/20080318/12
05833455:title=PythonでGrowlを叩く]を参考。
Growl に表示する画像、もうちょっとサイズが大きいのがあればいいんだけど。
http://friendfeed.com/static/images/icons/internal.png
import time import datetime import Growl from friendfeed import FriendFeed def ffeed(nick, key): session = FriendFeed(auth_nickname=nick, auth_key=key) def homefeed(): return session.fetch_home_feed() return homefeed def main(): img = Growl.Image.imageFromPath('./internal.png') g = Growl.GrowlNotifier( applicationName='FFgrowl', notifications=['Entry'] ) g.register() recent_entry_time = datetime.datetime.now() homefeed = ffeed("user", "key") while True: feed = homefeed() for entry in feed["entries"]: if recent_entry_time < entry["published"]: g.notify( noteType='Entry', title='%s %s' % (entry["user"]["nickname"], entry["service"]["name"]), description=entry["title"].encode("latin-1"), icon=img, sticky=False) recent_entry_time = feed["entries"][0]["published"] time.sleep(60) if __name__ == "__main__": main()
Lingr でニコニコ動画のサムネイルを表示
Lingr のチャットルームでニコニコ動画のリンクが書き込まれた時、サムネイルを自動挿入する GreaseMonkey スクリプトを作ったので公開。一応、Safari の GreaseKit でも動作するはず。
サムネイル生成部分はhttp://10coin.com/2007/07/30/115744 を使わせてもらっている。
// ==UserScript== // @name nicothumbnaillingr // @description nicovideo thumbnail for lingr // @include http://www.lingr.com/room/* // @exclude // ==/UserScript== (function () { function createIframeObj(href) { var video_id = href.replace('http://www.nicovideo.jp/watch/', ''); var iframeObj = document.createElement('iframe'); var style = iframeObj.style; style.width = '312px'; style.height = '176px'; style.borderWidth = '1px'; style.borderStyle = 'solid'; style.borderColor = '#ccc'; iframeObj.setAttribute('scrolling', 'no'); iframeObj.setAttribute('frameborder', 0); iframeObj.setAttribute('src', 'http://www.nicovideo.jp/thumb/' + video_id); return iframeObj; } function insertThumbnail() { var elems = document.getElementsByTagName('span'); for(var i = elems.length - 1; i > 0; i--) { var class_str = "" + elems[i].getAttribute('class'); if(class_str.match(/messageTextContainer/)) { var child_elems = elems[i].childNodes; for(var j = 0; j < child_elems.length; j++) { var href_str = "" + child_elems[j]; if(href_str.match(/http:\/\/www.nicovideo.jp\/watch\/sm[0-9]*/)){ var parent = child_elems[j].parentNode var href = child_elems[j].getAttribute('href'); var iframeObj = createIframeObj(href); parent.insertBefore(iframeObj, child_elems[j]); break; } } return; } } } function registerLingrEvent() { var w = typeof unsafeWindow != 'undefined' ? unsafeWindow : window; window.addEventListener('load', function(){ w.Chatroom.prototype.original_highlightLastMessage = w.Chatroom.prototype.highlightLastMessage; w.Chatroom.prototype.highlightLastMessage = function() { this.original_highlightLastMessage(); insertThumbnail(); } }, true); } function main() { registerLingrEvent(); } main(); })();