-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to allow login from google docs. Fixes unicode errors.
- Loading branch information
Showing
9 changed files
with
191 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,3 +89,4 @@ ENV/ | |
.ropeproject | ||
*.sublime-workspace | ||
*.sublime-project | ||
client_secret.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from __future__ import print_function | ||
import httplib2 | ||
|
||
from apiclient import discovery | ||
from xmd.google import get_credentials | ||
from oauth2client import tools | ||
|
||
try: | ||
import argparse | ||
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args() | ||
except ImportError: | ||
flags = None | ||
|
||
|
||
def main(): | ||
"""Shows basic usage of the Google Drive API. | ||
Creates a Google Drive API service object and outputs the names and IDs | ||
for up to 10 files. | ||
""" | ||
credentials = get_credentials(flags) | ||
http = credentials.authorize(httplib2.Http()) | ||
service = discovery.build('drive', 'v3', http=http) | ||
|
||
results = service.files().list( | ||
pageSize=10, fields="nextPageToken, files(id, name)").execute() | ||
items = results.get('files', []) | ||
if not items: | ||
print('No files found.') | ||
else: | ||
print('Files:') | ||
for item in items: | ||
print('{0} ({1})'.format(item['name'], item['id'])) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
from parser import transform, render, parse_file | ||
from . import google | ||
|
||
from .ipython import set_style | ||
set_style() | ||
del set_style |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from __future__ import print_function | ||
import os | ||
import httplib2 | ||
|
||
from apiclient import discovery | ||
from oauth2client import client | ||
from oauth2client import tools | ||
from oauth2client.file import Storage | ||
|
||
# If modifying these scopes, delete your previously saved credentials | ||
# at ~/.credentials/google2xmd.json | ||
privilege = ['', '.appdata', '.file', '.metadata', '.readonly'] | ||
location = 'https://www.googleapis.com/auth/drive' | ||
SCOPES = [location + priv for priv in privilege] | ||
|
||
CLIENT_SECRET_FILE = 'client_secret.json' | ||
APPLICATION_NAME = 'XMD' | ||
|
||
|
||
def get_credentials(flags=None): | ||
"""Gets valid user credentials from storage. | ||
If nothing has been stored, or if the stored credentials are invalid, | ||
the OAuth2 flow is completed to obtain the new credentials. | ||
Returns: | ||
Credentials, the obtained credential. | ||
""" | ||
home_dir = os.path.expanduser('~') | ||
credential_dir = os.path.join(home_dir, '.credentials') | ||
if not os.path.exists(credential_dir): | ||
os.makedirs(credential_dir) | ||
credential_path = os.path.join(credential_dir, 'google2xmd.json') | ||
|
||
store = Storage(credential_path) | ||
credentials = store.get() | ||
if not credentials or credentials.invalid: | ||
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) | ||
flow.user_agent = APPLICATION_NAME | ||
if flags: | ||
credentials = tools.run_flow(flow, store, flags) | ||
else: # Needed only for compatibility with Python 2.6 | ||
credentials = tools.run(flow, store) | ||
print('Storing credentials to ' + credential_path) | ||
return credentials | ||
|
||
|
||
def get_service(): | ||
credentials = get_credentials() | ||
http = credentials.authorize(httplib2.Http()) | ||
return discovery.build('drive', 'v3', http=http) | ||
|
||
|
||
def get_file(fileId, mimeType='text/plain'): | ||
req = get_service().files().export_media(fileId=fileId, mimeType=mimeType) | ||
return req.execute().decode('utf-8').strip(u'\ufeff') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os | ||
|
||
|
||
def in_ipython(): | ||
try: | ||
__IPYTHON__ | ||
return True | ||
except NameError: | ||
return False | ||
|
||
|
||
def set_style(): | ||
if not in_ipython(): | ||
return | ||
|
||
from IPython.display import HTML, display | ||
|
||
with open(os.sep.join(__file__.split(os.sep)[:-1] + ['xmd.css'])) as f: | ||
style = ( | ||
'<style type="text/css">' | ||
'{}' | ||
'</style>'.format(f.read()) | ||
) | ||
|
||
display(HTML(style)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.xmd-container{ | ||
position: relative; | ||
width: calc(100% - 250px); | ||
} | ||
|
||
.sidenote{ | ||
position:absolute; | ||
left: calc(100% + 15px); | ||
width: 230px; | ||
margin-top: -30px; | ||
font-size: 13px; | ||
color: #aaa; | ||
font-family: "Helvetica"; | ||
} | ||
|
||
.figure{ | ||
margin: 15px 0 30px 0; | ||
} | ||
|
||
.figure img{ | ||
width:100%; | ||
} | ||
|
||
.figure .caption{ | ||
margin-top:15px; | ||
text-align: center; | ||
color: #aaa; | ||
} |