-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkGoogleDocs.py
73 lines (63 loc) · 2.09 KB
/
checkGoogleDocs.py
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
73
#!/usr/bin/python
#
# Copyright 2013 National Evolutionary Synthesis Center (NESCent).
#
# 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 3 of the License, or
# (at your option) any later version.
#
# This program 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 program. If not, see <http://www.gnu.org/licenses/>.
import sys
import getopt
import tempfile
import gdata.docs.service
import gdata.docs.client
import checkData
import exportGoogleDocs
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], '', ['user=', 'pw='])
except getopt.error, msg:
print 'python checkGoogleDocs.py --user [username] --pw [password]'
sys.exit(2)
user = None
pw = None
key = ''
# Process options
for option, arg in opts:
if option == '--user':
user = arg
elif option == '--pw':
pw = arg
if user is None or pw is None:
print 'python checkGoogleDocs.py --user [username] --pw [password] '
sys.exit(2)
# Source is just a name identifying this application
client = gdata.docs.client.DocsClient(source='nescent-parkNotebooks-v1')
client.ssl = True
client.http_client.debug = False
try:
client.ClientLogin(user,pw,client.source)
except gdata.service.BadAuthentication:
print "Error logging in with these credentials"
return
# Make a temp directory
tempdir = tempfile.mkdtemp()
# export the docs there
titleSearchStr='ftbms010010020_1'
feed = client.GetResources(uri='/feeds/default/private/full/-/spreadsheet?title='+titleSearchStr)
if not feed.entry:
print 'No spreadsheet titled '+titleSearchStr+'\n'
return
exportGoogleDocs.DownloadFeed(client, feed, tempdir)
# run checkdata on it
checkData.checkDirectory(tempdir)
if __name__ == '__main__':
main()