Skip to content

Commit

Permalink
replace gspread with pygsheets
Browse files Browse the repository at this point in the history
  • Loading branch information
steveoh committed Feb 21, 2018
1 parent d04856d commit 6f421cf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -7,4 +7,4 @@ node_modules/
Gemfile.lock
*.pyc

scripts/gspread-31a626054f8c.json
scripts/*.json
16 changes: 5 additions & 11 deletions scripts/datatable.py
Expand Up @@ -10,8 +10,7 @@
from os import rename
from os.path import dirname, join

import gspread
from oauth2client.service_account import ServiceAccountCredentials
import pygsheets
from pydash.strings import start_case


Expand Down Expand Up @@ -68,15 +67,14 @@ def webapp_link(value):

return '<a href="{}" class="pull-right"><i class="fas fa-globe fa-fw" alt="website link"></i></a>'.format(value.strip())

return OrderedDict([('category', utf8_encode(category)), ('name', should_link(start_case(name.replace('_', '')))),
return OrderedDict([('category', utf8_encode(category)), ('name', should_link(start_case(name.replace('_', ' ')))),
('agency', utf8_encode(item[indices['data_source']])), ('description', utf8_encode(item[indices['description']])), ('service', ''.join(
[endpoint_link(item[indices['endpoint']]), webapp_link(item[indices['web_app']])]))])


def get_sheet_data(gc, sheet_id, worksheet_id):
worksheet = gc.open_by_key(sheet_id).worksheet(worksheet_id)

data = worksheet.get_all_values()
worksheet = gc.open_by_key(sheet_id).worksheet_by_title(worksheet_id)
data = worksheet.get_all_values(returnas='matrix')

header = data.pop(0)
indices = {
Expand Down Expand Up @@ -134,13 +132,9 @@ def create(data):


if __name__ == '__main__':
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name(join(dirname(__file__), 'gspread-31a626054f8c.json'), scope)

gc = gspread.authorize(credentials)
gc = pygsheets.authorize(service_file='client_secret.json')

data = get_sheet_data(gc, '11ASS7LnxgpnD0jN4utzklREgMf1pcvYjcXcIcESHweQ', 'SGID Stewardship Info')

data = filter(lambda x: len(x['name']) > 0, data)
html = create(data)

Expand Down
3 changes: 1 addition & 2 deletions scripts/requirements.txt
@@ -1,4 +1,3 @@
datatable
gspread==0.4.1
oauthclient==4.0.0
pygsheets==1.1.3
pydash==3.4.7

0 comments on commit 6f421cf

Please sign in to comment.