Code Monkey home page Code Monkey logo

Comments (2)

yoavaviram avatar yoavaviram commented on June 20, 2024

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 <
[email protected]

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

from python-google-spreadsheet.

gekkoman avatar gekkoman commented on June 20, 2024

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

from python-google-spreadsheet.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.