Commits

Ajay Roopakalu  committed 127e05b Merge

Merge pull request #1 from hrios/master

Added keys module (by hrios) to facilitate getting client data if keys file does not exist.

  • Participants
  • Parent commits d4a2307, 034cc4c

Comments (0)

Files changed (2)

+class Auth():
+
+    def __init__(self, key_file):
+
+        try:
+           with open(key_file, 'r') as self.f:
+            self.ff = self.f.read().split("\n")
+        
+            self.clientid = self.ff[0]
+            self.clientsecret = self.ff[1]
+            self.apikey = self.ff[2]
+            
+        except IOError:
+            self.clientid = raw_input("Enter your clientID: ")
+            self.clientsecret = raw_input("Enter your client secret: ")
+            self.apikey = raw_input("Enter your API key: ")
+            
+    def writeAuth(self):
+        self.auth = open('keys.txt', 'w')
+        self.auth.write(clientid)
+        self.auth.write(clientsecret)
+        self.auth.write(apikey)
+        self.auth.close()
+
+    def getClientID(self):
+        return self.clientid
+    def getClientSecret(self):
+        return self.clientsecret
+    def getApiKey(self):
+        return self.apikey

File src/tasky.py

 import time
 import os
 import readline
+import keys
 
 parser = None
 arguments = False
     sys.argv = vars(parser.parse_args())
 
 print 'Verifying authentication...'
-f = open('keys.txt', 'r')
+f = keys.Auth('keys.txt')
 
 # OAuth 2.0 Authentication
 FLOW = OAuth2WebServerFlow(
-    client_id = f.readline(),
-    client_secret = f.readline(),
+    client_id = f.getClientID(),
+    client_secret = f.getClientSecret(),
     scope = 'https://www.googleapis.com/auth/tasks',
     user_agent='Tasky/v1')
 
 http = credentials.authorize(http)
 
 # The main Tasks API object
-service = build(serviceName='tasks', version='v1', http=http,
-       developerKey=f.readline())
-f.close()
+service = build(serviceName='tasks', version='v1', http=http, developerKey = f.getApiKey())
+
 
 TaskLists = {}
 IDToTitle = {}