/
google_docs_up
executable file
·73 lines (63 loc) · 2.21 KB
/
google_docs_up
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python2.5
# -*- python -*-
import gdata.docs.service
import sys, os
# 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.
client.ClientLogin('your@gmail.account', 'PASSWORD')
# Upload Specified File
filepath = sys.argv[1]
filename = filepath.split("/")[-1]
# Determine FILETYPES
suffix = filename.split(".")[-1].upper()
ft = None
uploadfunc = None
"""
SUPPORTED_FILETYPES = {
'CSV': 'text/csv',
'TSV': 'text/tab-separated-values',
'TAB': 'text/tab-separated-values',
'DOC': 'application/msword',
'DOCX': ('application/vnd.openxmlformats-officedocument.'
'wordprocessingml.document'),
'ODS': 'application/x-vnd.oasis.opendocument.spreadsheet',
'ODT': 'application/vnd.oasis.opendocument.text',
'RTF': 'application/rtf',
'SXW': 'application/vnd.sun.xml.writer',
'TXT': 'text/plain',
'XLS': 'application/vnd.ms-excel',
'XLSX': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'PDF': 'application/pdf',
'PNG': 'image/png',
'PPT': 'application/vnd.ms-powerpoint',
'PPS': 'application/vnd.ms-powerpoint',
'HTM': 'text/html',
'HTML': 'text/html',
'ZIP': 'application/zip',
'SWF': 'application/x-shockwave-flash'
}
"""
ft = suffix
uploadfunc = client.Upload
# Filetype Exceptions
if suffix in ('PPTX'):
ft = 'PPT'
print "Filetype: %s" % (ft)
if ft not in gdata.docs.service.SUPPORTED_FILETYPES :
print "Filetype %s not supported in Google Docs." % (ft)
sys.exit(1)
# Execute Upload
print (filepath, filename, suffix)
ms = gdata.MediaSource(file_path=filepath , content_type=gdata.docs.service.SUPPORTED_FILETYPES[ft])
entry = uploadfunc(media_source=ms, title=filename)
print 'Document now accessible online at:\n'
print ' %s\n' % (entry.GetAlternateLink().href)
# Print List
print "Current Documents list: \n"
# 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