Skip to content

Commit

Permalink
(feat) add server logging
Browse files Browse the repository at this point in the history
  • Loading branch information
azai91 committed Dec 4, 2015
1 parent 8eac17b commit 8651889
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
SCOPE = 'https://www.googleapis.com/auth/drive.readonly'
REDIRECT_URI = 'http://127.0.0.1:1337'

AUTH_URL = 'https://accounts.google.com/o/oauth2/auth?scope=%s&redirect_uri=%s&response_type=code&client_id=%s&access_type=offline&approval_prompt=force' % (SCOPE, REDIRECT_URI, CLIENT_ID)
AUTH_URL = 'https://accounts.google.com/o/oauth2/auth?scope=%(scope)s&redirect_uri=%(redirect_uri)s&response_type=code&client_id=%(client_id)s&access_type=offline&approval_prompt=force' % {'scope' : SCOPE, 'redirect_uri' : REDIRECT_URI, 'client_id' : CLIENT_ID}

TOKEN_URL = 'https://www.googleapis.com/oauth2/v3/token'
FILES_URL = 'https://www.googleapis.com/drive/v2/files?fields=items'
Expand Down
13 changes: 13 additions & 0 deletions src/logging.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
INFO:root:Configuring server
INFO:root:GET request received
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): www.googleapis.com
DEBUG:workflow:Password exists : com.drive.azai91:drive_access_token
DEBUG:workflow:Got password : com.drive.azai91:drive_access_token
DEBUG:workflow:Deleted password : com.drive.azai91:drive_access_token
DEBUG:workflow:save_password : com.drive.azai91:drive_access_token
DEBUG:workflow:Password exists : com.drive.azai91:drive_refresh_token
DEBUG:workflow:Got password : com.drive.azai91:drive_refresh_token
DEBUG:workflow:Deleted password : com.drive.azai91:drive_refresh_token
DEBUG:workflow:save_password : com.drive.azai91:drive_refresh_token
INFO:root:Account Saved
INFO:root:Server started on port 1337
8 changes: 8 additions & 0 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@
import urlparse
from time import sleep
import subprocess
import logging
import sys

logging.basicConfig(filename='logging.log',level=logging.INFO)
logging.info('Configuring server')
class HandlerClass(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(s):
logging.info('GET request received')
try:
code = urlparse.urlparse(s.path)[4].split('=')[1]
user_credentials = Drive.exchange_tokens(code)
subprocess.call(['python','./drive_refresh.py'])
sys.stdout.write('Account Saved')
logging.info('Account Saved')
s.wfile.write('Your code has been saved in Alfred')
except:
s.wfile.write('Error with setting code')
Expand All @@ -24,3 +31,4 @@ def do_GET(s):
httpd = ServerClass(server_address, HandlerClass)
httpd.timeout = 20
httpd.handle_request()
logging.info('Server started on port 1337')

0 comments on commit 8651889

Please sign in to comment.