-
Notifications
You must be signed in to change notification settings - Fork 1
/
spreadsheets_connect.py
78 lines (52 loc) · 1.77 KB
/
spreadsheets_connect.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
74
75
76
77
78
#------author--->black-perl-------
#------written @ 17-10-2013---
from gdata.spreadsheet.service import *
from getopt import getopt,error
from getpass import getpass
import sys
from crud import CRUD
#defining gloabal variables
_id=" "
_password=" "
client=None
def userCredentials():
try:
opts,arguments=getopt(sys.argv[1:]," ",["user="])#username,opt are locals for functions
except error:
print "----RUN AS: python spreadsheets_connect.py --user [username]"
sys.exit()
if len(opts)>0:#because if not argument given to --user error is there
for user,username in opts:
if user!="--user":
print "----RUN AS: python spreadsheets_connect.py --user [username]"
sys.exit()
else:
global _id
_id=username
elif len(opts)==0:
print "----RUN AS: python spreadsheets_connect.py --user [username]"
sys.exit()
def promptForPassword():
global _password
_password=getpass("enter password for:{0}---->".format(_id))
def connect(userid,password):
global client#we need to define client to global
client=SpreadsheetsService()
client.email=userid
client.password=password
client.source = 'Spreadsheets GData Sample'
client.ProgrammaticLogin()
def clientConnect():
userCredentials()
if "@" not in _id:
print"----RUN AS: python spreadsheets_connect.py --user [username] and enter valid username"
sys.exit()
else:
promptForPassword()
connect(_id,_password)
print "----connection established------"
return client
if __name__=="__main__":
a=clientConnect()
mycrud=CRUD(a)
mycrud.run()