Created
February 26, 2012 19:58
-
-
Save j3tm0t0/1918684 to your computer and use it in GitHub Desktop.
Monitor Google Reader Unread Count with CloudWatch
This file contains 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
#!/usr/bin/python | |
# coding=utf-8 | |
# http://moimoitei.blogspot.com/2011/03/google-python-google-reader-api.html を参考にさせていただきました | |
import gdata.service | |
import json | |
import re | |
import boto | |
config = { 'Email': 'changeme@example.com', 'Passwd': 'password' } | |
AWS_ACCESS_KEY = "AWS_ACCESS_KEY" | |
AWS_SECRET_KEY = "AWS_SECRET_KEY" | |
cw = boto.connect_cloudwatch(AWS_ACCESS_KEY, AWS_SECRET_KEY) | |
# Google Reader サービス設定 | |
service = gdata.service.GDataService(account_type='GOOGLE', | |
service='reader', | |
server='www.google.com', | |
source='MyReaderHoge') | |
# Google アカウント設定とログイン | |
service.ClientLogin(config['Email'],config['Passwd']) | |
# 認証トークン(SIDの値) | |
# print service.GetClientLoginToken() | |
# 書き込み用のトークンの取得 | |
token = service.Get('/reader/api/0/token',converter=lambda x:x) | |
# print "token:", token | |
query = gdata.service.Query(feed='/reader/api/0/unread-count', | |
params={'all':'true', 'output':'json'}) | |
feed = json.loads(service.Get(query.ToUri(), converter=lambda x:x)) | |
unreadcounts = feed['unreadcounts'] | |
# 全体の未読数を一番前に移動しとく | |
for i, item in enumerate(unreadcounts): | |
if re.match(r'^user/\d+/state/com.google/reading-list$',item['id']): | |
unreadcounts.pop(i) | |
unreadcounts.insert(0,item) | |
break | |
# 全体の未読数 | |
unread=int(unreadcounts[0]['count'] if len(unreadcounts) > 0 else 0) | |
print unread | |
cw.put_metric_data("Google/Reader","Unread" , unread ,[], "Count", {"label":"all"}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment