2009/09/08

analytics api python

Google Analytics のデータを Web から取るのが嫌になってて
API が用意されたのは知っていたのに放置していたんですが
そろそろ手を付けてみるかと思って検索してみました

何も知らんかったのでとりあえず検索したら
Juiced Google Analytics Python API: Juice Analytics
がひっかかったんだけど最初んとこで
Due to the release of an official Google Analytics Data Export API, this module is now deprecated. We have an alternative python module based upon the real analytics API here, and an exploring tool with an automatic code generation capability here.
って書いてあるんで
素直に飛びました
suryasev/python-degapi @ GitHub
で、gdata っての入れろって書いてあるから入れようとしてみると
$ easy_install gdata
Searching for gdata
Reading http://pypi.python.org/simple/gdata/
Reading http://code.google.com/p/gdata-python-client/
Best match: gdata 2.0.2
Downloading http://gdata-python-client.googlecode.com/files/gdata-2.0.2.zip
Processing gdata-2.0.2.zip
Running gdata-2.0.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-11Yjnd/gdata-2.0.2/egg-dist-tmp-EM1MAM
zip_safe flag not set; analyzing archive contents...
Adding gdata 2.0.2 to easy-install.pth file

Installed /usr/local/lib/python2.6/site-packages/gdata-2.0.2-py2.6.egg
Processing dependencies for gdata
Finished processing dependencies for gdata
2.0.2 ってのが入って書いてあるのと全然違う

gdata って何だよ! と思って調べたら
Getting Started with the Google Data Python Library - Google Data APIs - Google Code
何もーちゃんとしたのがあるんじゃない
もの知らんと怖いなぁと思いました

とりあえずカレンダーでも読めるようになりたいヨ! と思ったので
ドキュメントを眺めつつ今年と来年の祝日を取ろうとしたんですが
import gdata.calendar.service

def getHolidays(year=2009):
cs = gdata.calendar.service.CalendarService()
q = gdata.calendar.service.CalendarEventQuery(
'japanese__ja@holiday.calendar.google.com', 'public', 'basic')
"""
>>> q.ToUri()
'http://www.google.com/calendar/feeds/japanese__ja%40holiday.calendar.google.com/public/basic'
"""
q.start_min = str(year) + '-01-01'
q.start_max = str(year) + '-12-31'
feed = cs.CalendarQuery(q)
return [i.title.text for i in feed.entry]

if __name__ == "__main__":
print " ". join(sorted(getHolidays(2009)))
print " ". join(sorted(getHolidays(2010)))
ん〜、日付の取り方が分からない
when とか入ってないし、繰り返しだから??
2009 年の春分の日も無くなってるんだよなぁ

あれ? Analytics は??
trail a trend: Google Analytics Data API を試す
trail a trend: Google Analytics Data APIを試す。続き
この辺見たらいいと思うヨ!!

0 件のコメント:

コメントを投稿