Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some feature enhancements #3

Closed
gekkoman opened this issue Jul 11, 2012 · 2 comments
Closed

Some feature enhancements #3

gekkoman opened this issue Jul 11, 2012 · 2 comments

Comments

@gekkoman
Copy link

Yoav,

thanks for your package. I was half way writing basically the same when I stumbled on yours which saved me a bit of time.

I however needed some more functionality which you may wish to implement in your package.

My application requires unique row identification for later retrieval.

Sorting through the whole listfeed seemed grossly inefficient, so I am using the following as workaround.

identification:

sheet=api.get_worksheet(spreadsheet, worksheet)
rows = sheet.get_rows()
for i, row in enumerate(rows):
id = sheet._get_row_entries(sheet.query)[i].id.text.rsplit("/",1)[1] #NAUGHTY!

retrieval:
rowkey='4su05' #unique row key
sheet=api.get_worksheet(spreadsheet, worksheet)

fudge to get single row only

sheet.keys['row_id']=rowkey #NAUGHTY!
sheet.entries=[sheet.gd_client.GetListFeed(**sheet.keys)] #NAUGHTY!
rows=sheet.get_rows()

Now you can update etc as intended

Regards

Tarek

@yoavaviram
Copy link
Owner

Hi Tarek,

Thank you for using the package and for taking the time to write to me.

I was also considering adding row ID's to the results in order to simplify
updates and deletes.
The problem with the method you suggested is that it adds an
extra round-trip to the server on every update. I tried implementing a
version that does not require that all the time. Please take a look at the
better_row_idhttps://github.com/yoavaviram/python-google-spreadsheet/tree/better_row_idbranch
on GitHub and let me know what you think.

Yoav

On Wed, Jul 11, 2012 at 2:21 AM, gekkoman <
reply@reply.github.com

wrote:

Yoav,

thanks for your package. I was half way writing basically the same when I
stumbled on yours which saved me a bit of time.

I however needed some more functionality which you may wish to implement
in your package.

My application requires unique row identification for later retrieval.

Sorting through the whole listfeed seemed grossly inefficient, so I am
using the following as workaround.

identification:

sheet=api.get_worksheet(spreadsheet, worksheet)
rows = sheet.get_rows()
for i, row in enumerate(rows):
id = sheet._get_row_entries(sheet.query)[i].id.text.rsplit("/",1)[1]
#NAUGHTY!

retrieval:
rowkey='4su05' #unique row key
sheet=api.get_worksheet(spreadsheet, worksheet)
#fudge to get single row only
sheet.keys['row_id']=rowkey #NAUGHTY!
sheet.entries=[sheet.gd_client.GetListFeed(**sheet.keys)] #NAUGHTY!
rows=sheet.get_rows()

Now you can update etc as intended

Regards

Tarek


Reply to this email directly or view it on GitHub:
#3

@gekkoman
Copy link
Author

Yoav,

my app is async......I have the row ID printed on paper and at some time later update the record using the row ID as the key.

As such i need to retrieve a single entry from Google based on its row ID and update it, without any preloaded entries in the cache.

The private method "_get_row_entry_by_id" in your better_row_id code does this. i.e. if you call this function with any empty cache you will get the record required.

I like the fact that you populate a cache so one can do things locally, and the simplicity of the process. I was going the same way because I was finding the google API to be not the most user friendly thing out there.

To me the ideal API solution would be one more level of abstraction from current, that is we do operations at row level.

eg

rows=sheet.get_rows(query) #returns a list of row objects
for row in rows:
row.field['name']=something
id=row.id #google row ID
idx=row.index #cache index
csum=row.csum #csum used to establish if row is dirty - i.e. requiring update
print(row.field) #print out the row dictionary

row.update() #update single row if necessary
rows.update() #update modified rows only, match current csum against stored csum

singlerow=sheet.get_row(id)
singlerow.field['whatever']='something'
singlerow.update()

This way you don't have to keep track of indexes, keys etc at all for doing updates.

You could also do inserts/deletes etc in this way

n=sheet.row()
n.field['name']='something'
n.insert() #actually a wrapper to n.update()
n.delete()

This is however more complex and breaks the current API completely.

Tarek

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants