èªåã¯ãå人çãªæ°ã¥ããããã¹ããã¡ã¤ã«ã«ã¡ã¢ããããã¦ãããã§ããã
ã¡ã¼ã«ãã¯ã¦ãã使ã£ã¦ãã¾ããããããçµç±ã¨ãã¼ã«ã«ãã¡ã¤ã«ã§ã¯ãã©ããã¦ãå¿çé度ã«éããåºã¦ãã¾ãã¾ããããã
ãããã£ã¦ãæ¸ãçããããã¹ããã¡ã¤ã«ã§ãããä½æã¾ã§ããã¼ã«ã«ã«ç½®ãã¦ããã®ãå«ãªãã§ããã
ãã©ã¤ãã¼ããªãããã¹ãã¬ã¼ã¸ã«çªã£è¾¼ãã§ããã°ããã¼ã«ã«ãã·ã³ãå£ããéã®å¾©æ§ããã¿ãã¬ãããªã©ã®å¥ã®ãã·ã³ãããåç
§ã§ããã®ã§ã便å©ã«ãªã訳ã§ãã
ãããã¹ãã¬ã¼ã¸ã«çªã£è¾¼ãã ãã¼ã¿ã®æ¤ç´¢æ§ã§ãé常ã«ä¾¿å©ãªã®ã¯ãä»ã®æãGoogle ããã¥ã¡ã³ããEvernote辺ãããªï¼ã¨æãã¦ãã¾ãã
ç¹ã«ãGoogle ããã¥ã¡ã³ãã¯ãæ¤ç´¢ããã«æ©ãªã®ã§ãçµæ§ãæ°ã«å
¥ãã§ãã
(Microsoftããã®SkyDriveã¯å®¹éã¯ãã«ã¤ããªã®ã§ãããæ¤ç´¢ãèªåã®ã¢ãããããã®ã«çµããªãã®ãããã¯ï¼ä½ãæ¹æ³ãããã®ããªãï¼)
(ã¡ãªã¿ã«ãYahooã¯ãµã¼ãã¹è¦ç´ããã³ãã³å¤ããã®ã§ãä¸å®ã§ä½¿ããªã)
ã¨ãã訳ã§
ã¨ãã訳ã§ãããã¹ããã¡ã¤ã«ãGoogle ããã¥ã¡ã³ãã«èªåã¢ãããã¼ããããã¨æãã¾ããã
è¦ããã«ãã¿ã¹ã¯ã¹ã±ã¸ã¥ã¼ã©çã§ããã¼ã«ã«ã«ç½®ããããã¹ããã¡ã¤ã«ãå®æçã«ã¢ãããã¼ãï¼æ´æ°ãã¡ãããã£ã¦è¨³ã§ãã
å½åã¯ãé©å½ãªã½ããã使ãããï¼ã¨æã£ã¦ãããã§ããããããã¨çµæ§æ¥½ã«å®è£ ã§ããäºãå¤ã£ãã®ã§ãåå¼·ãã¦ãèªä½ããäºã«ãã¾ããã
- Client Libraries and Sample Code - Google Documents List API - Google Code
http://code.google.com/intl/ja/apis/documents/code.html - Python Language Guide (v1.0) - Google Documents List Data API v1.0 - Google Code
http://code.google.com/intl/ja/apis/documents/docs/1.0/developers_guide_python.html - Google Document ã«ãã¡ã¤ã«ãã¢ãããã¼ãããããããä½ã£ã¦ã¿ã - Limitã®æ¥è¨
http://d.hatena.ne.jp/limitusus/20090929/1254232748 - imageryblog: Google ããã¥ã¡ã³ãã«ãã¡ã¤ã«ãã¢ãããã¼ã,ãã¦ã³ãã¼ãããæ¹æ³ #googledocs
http://blog.firefly-vj.net/2011/08/google-googledocs.html - Google Documents List Data API v3.0 ã python ããå©ç¨ãã¦ã¿ãã (tonextone.com/type/)
http://tonextone.com/type/2010/06/20-0028.html
ã¯ã©ã¤ã¢ã³ãã®ã©ã¤ãã©ãªã¯ãClient Libraries and Sample Code - Google Documents List API - Google Codeã®Downloadããåå¾ãã¾ãã
èªåãåå¾ããã®ã¯ãgdata-2.0.14.zip ã§ããã
ãã¦ã³ãã¼ããã¦ãsetup.pyã§installããã°ã¤ã³ã¹ãã¼ã«ããã¾ãã
I:\Wacky\src\test\google\gdata-2.0.14>python setup.py install ... byte-compiling C:\tool2\Python27\Lib\site-packages\gdata\youtube\__init__.py to __init__.pyc byte-compiling C:\tool2\Python27\Lib\site-packages\gdata\__init__.py to __init__ .pyc running install_egg_info Writing C:\tool2\Python27\Lib\site-packages\gdata-2.0.14-py2.7.egg-info
å¾ã¯ãä¸ã®ãªã³ã¯ã§ç´¹ä»ããã¦ãããµã³ãã«ã³ã¼ããå
ã«APIãå©ãã°OKã§ãã
ã§ã¯ãæ©éä»åä½ã£ãã³ã¼ãã示ãã¾ãã
#!/bin/env python # -*- encoding: cp932 -*- """ Google Documentã«ããã¹ããã¡ã¤ã«ãã¢ãããã¼ããã ãªããããã¹ããã¡ã¤ã«ã¯ãutf-8å½¢å¼ãããã©ã«ãã§ããã(Google Documentã®å ´å) """ import sys import os import os.path import pdb import gdata.docs import gdata.docs.service def get_exe_dir_name(): """å®è¡ã¹ã¯ãªããã®ãã©ã«ããåå¾""" return os.path.abspath(os.path.dirname(__file__)) def copy_to_utf8(src_fpath, dst_dir=None): """src_fpath(ã³ãã¼å ã®ãã¡ã¤ã«ãã¹)ããdst_dir(ã³ãã¼å ãã£ã¬ã¯ããª)ã«ãutf-8å¤æã³ãã¼ãã""" fname = os.path.split(src_fpath)[1] if dst_dir == None: dst_dir = get_exe_dir_name() dst_fpath = os.path.join(dst_dir, fname) s = "nkf32 -w8 \"%s\" > \"%s\"" % (src_fpath, dst_fpath) print "call: ", s os.system(s) return dst_fpath def list_file(cli): """Google Documentã®ãã¡ã¤ã«ä¸è¦§ãå¾ã""" i = 0 for e in cli.GetDocumentListFeed().entry: i = i + 1 print "%02d : file [%s][%s]" % (i, e.title.text.decode('utf-8'), e.GetDocumentType()) def list_dir(cli): """Google Documentã®ãã©ã«ãä¸è¦§(ã³ã¬ã¯ã·ã§ã³)ãå¾ã""" i = 0 q = gdata.docs.service.DocumentQuery(categories=['folder'], params={'showfolders': 'true'}) for e in cli.Query(q.ToUri()).entry: i = i + 1 print "%02d : dir [%s]" % (i, e.title.text.decode('utf-8').encode('cp932')) def find_file(cli, name): """Google Documentã«æå®ããååã®ãã¡ã¤ã«ãããã調ã¹ããããã°ãªãã¸ã§ã¯ãããç¡ããã°Noneãè¿ã""" for e in cli.GetDocumentListFeed().entry: if e.title.text.decode('utf-8') == unicode(name, 'cp932'): return e return None def upload_text(cli, fpath, name=None): """Google Documentã«ããã¡ã¤ã«ãã¢ãããã¼ããããæ¢ã«ãã¡ã¤ã«ãããã°ç½®ãæãã \arg fpath ã¢ãããã¼ãå ã®ãã¡ã¤ã«ãã¹ \arg name ã¢ãããã¼ãæã®åå """ if name == None: name = os.path.split(fpath)[1] print "ã¢ãããã¼ãä¸(%s, %s)..." % (name, fpath) ms = gdata.MediaSource(file_path=fpath, content_type=gdata.docs.service.SUPPORTED_FILETYPES['TXT']) exist_file = find_file(cli, name) e = None if exist_file == None: print " new upload file!!" e = cli.Upload(ms, unicode(name, 'cp932')) else: print " replace file!!" e = cli.Put(ms, exist_file.GetEditMediaLink().href) print " OK!!" print " href=%s" % (e.GetAlternateLink().href) def main(argv): print "[%s]ã®ãã¡ã¤ã«ãä½æ¥ãã©ã«ãã«ã³ãã¼ä¸" % argv[1] up_file = copy_to_utf8(argv[1]) print "upload file:[%s]" % up_file print "Google Documentã«ã¢ã¯ã»ã¹ä¸...", cli = gdata.docs.service.DocsService() cli.ClientLogin("<ã¢ã«ã¦ã³ã>", "<ãã¹ã¯ã¼ã>") print "ã¢ã¯ã»ã¹å®äº!!" print "\n--- Google Document List ---" list_dir(cli) list_file(cli) print "" upload_text(cli, up_file, None) print "ã¢ãããã¼ãå®äº!!" if __name__ == "__main__": argv = sys.argv print "argc=%d" % len(argv) for i in range(len(argv)): print "%d-[%s]" % (i, argv[i]) main(argv)
使ãæ¹ã¯ãã¢ãããã¼ããããããã¹ããã¡ã¤ã«ã®ãã¹ã第1å¼æ°ã«ä¸ããã ãã§ãã
ã¹ã¯ãªããã®ãã©ã«ãã«ãnkf32ã§UTF-8å¤æããããã¹ããã¡ã¤ã«ãä¸æ¦é
ç½®ããããããGoogle ããã¥ã¡ã³ãã«ã¢ãããã¼ãããä»æãã§ãã
æå¾ã«
ä¸å¿ä½è«ã§ãã
Googleããã¥ã¡ã³ãã¯ãããã¹ããã¡ã¤ã«ã¯UTF-8ãåæã«ãªã£ã¦ããã¿ããã§ãã
ãªã®ã§ãã¹ã¯ãªããã§ã¯ãWindowsçã®nkf32ã使ã£ã¦ãä¸æ¦UTF-8ã«å¤æãã¦ããã¢ãããã¼ãããããã«ãã¦ãã¾ãã
ããããªãã¨ãã¢ãããã¼ããããã¡ã¤ã«ãåç
§ãããã¨ãã¦ãæååãã«ééãã¡ããã¾ãã
å¾ãUploadã¨Replaceããã¾ã使ããªãã¨ãåããã¡ã¤ã«åã§ããã³ãã³Uploadãããã¡ã«é¥ãã¾ãã®ã§ãæ°ãã¤ãã¦ãã ããã
(æåãåãååã®ãã¡ã¤ã«ãé£ç¶ãã¦è¡¨ç¤ºãããã®ã§ãä½ãèµ·ããã®ã ããã¨èãããã§ãã¾ã£ã)
ã§ãã§ãã