Skip to content

Commit

Permalink
url method
Browse files Browse the repository at this point in the history
  • Loading branch information
dwhodges2 committed Aug 30, 2019
1 parent e86e0a0 commit c50f33a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -36,8 +36,12 @@ This enables several methods on the dataSheet class:

### Additional Subclasses

* `.id`: Returns id part of dataSheet
* `.range`: Returns range part of dataSheet
* `.initInfo`: Returns dictionary of metadata about sheet (all tabs, not just the one defined in 2nd arg of dataSheet).
* `.initTabs`: Returns a list of names of tabs in spreadsheet.
* `.url`: Returns public url of sheet of form https://docs.google.com/spreadsheets/d/{sheet_id}/edit#gid={tab_id}


## Sample Commands

Expand Down
1 change: 1 addition & 0 deletions sample.py
Expand Up @@ -7,4 +7,5 @@

print(x)

print('Go to ' + my_sheet.url + ' to see the data!')

10 changes: 9 additions & 1 deletion sheetFeeder.py
Expand Up @@ -28,7 +28,7 @@ def __init__(self, id, range):
self.range = range
self.initInfo = getSheetInfo(id)
self.initTabs = getSheetTabs(id)
# self.initData = getSheetData(id,range)
self.url = getSheetURL(id,range)

def clear(self):
sheetClear(self.id, self.range)
Expand Down Expand Up @@ -131,6 +131,14 @@ def getSheetDataColumns(sheet,range):
response = []
return response

def getSheetURL(sheet,range):
# Pull the title of tab from the range
tab_name = range.split('!')[0]
sheet_info = getSheetInfo(sheet)['sheets']
# Look for sheet matching name and get its ID
sheet_id = next( i['properties']['sheetId'] for i in sheet_info if i['properties']['title'] == tab_name )
the_url = 'https://docs.google.com/spreadsheets/d/' + str(sheet) + '/edit#gid=' + str(sheet_id)
return the_url

def sheetClear(sheet,range):
service = googleAuth()
Expand Down

0 comments on commit c50f33a

Please sign in to comment.