사용자:풀빵/스크립트작업실
< 사용자:풀빵
GPL, MIT LICENSE 하에서, 누구나 쓰셔도 됩니다.
/* Copyright (C) 2007-2008 풀빵 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this software; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */
#!/usr/bin/python
# -*- coding: utf-8 -*-
import user_docs_config
# (C) PpulBbang 풀빵, 2009
#
# Distributed under the terms of the MIT license.
import os
import gdata
import gdata.service
import gdata.docs.service
def send(filepath, title):
application_name="com.mydomain.app.google.senddocs-v0100"
email = user_docs_config.g_username
password = user_docs_config.g_password
# Create a client class which will make HTTP requests with Google Docs server.
client = gdata.docs.service.DocsService()
# Authenticate using your Google Docs email address and password.
try:
client.ClientLogin(user_docs_config.g_username, user_docs_config.g_password)
except gdata.service.CaptchaRequired:
print '[Send Docs]'
print 'Please visit : ' + client.captcha_url
answer = raw_input('Answer to the challenge? ')
client.ClientLogin(email, password, source=application_name, captcha_token=client.captcha_token, captcha_response=answer)
except gdata.service.BadAuthentication:
exit('Users credentials were unrecognized')
except gdata.service.Error:
exit('Login Error')
# Query the server for an Atom feed containing a list of your documents.
documents_feed = client.GetDocumentListFeed()
# Loop through the feed and extract each document entry.
for document_entry in documents_feed.entry:
# Display the title of the document on the command line.
print document_entry.title.text
ms = gdata.MediaSource(file_path=filepath, content_type=gdata.docs.service.SUPPORTED_FILETYPES['TXT'])
entry = client.Upload(ms, title)
print 'Document now accessible online at:', entry.GetAlternateLink().href
def selftest():
DIR_NAME = "./w/"
path = DIR_NAME
dir_list = os.listdir(path)
for fname in dir_list:
print fname
filename = raw_input('File name? (not including ./w/) ')
filename = '%s%s' % (DIR_NAME, filename)
title = filename.replace('txt', '')
send(filename, title)
if __name__ == '__main__':
selftest()