Mike Levin SEO

Future-proof your technology-skills with Linux, Python, vim & git... and me!

Using a List of Dicts in Python For GData InsertRow

by Mike Levin SEO & Datamaster, 07/12/2012

Okay, yesterday I made remarkable progress on the next big thing in 360iTiger: the ezscrape tab. I got regular expression support in just before leaving yesterday, and today it’s already 3:00 PM, and I’m just getting started. It’s been a very different day today than the rest of the week—full of meetings and surprises. What is the most efficient path to hitting the ezscrape project home?

I can move functions over into ezscrape at any time—”porting” existing functions, as it were. But I can only do the tab creating and loading-in support with focus and clarity. Try to get that done! 1, 2, 3… 1?

Well, I have this concept of a booltab that makes new tabs, which requires a document key, a name, and a list of column names. So at bare minimum, booltab will create a new worksheet and set up a bunch of columns. If a dictionary parameter is passed in, in rebuilds the name/val pairs of the dictionary object into a list of dictionaries, each one has a col1=val1, col2=val2 structure. So, it directly supports the creation of other tabs that are much like the config tab itself, with a simple 2-column name/value pair arrangement. It breaks down on greater than two columns.

Hmmmm. Interesting! If booltab is fed a column list with more than 2 columns, it will still create them. It does the proper setup for multiple columns, but just not populating the rows. I have more that 2 columns being populated in the auto-documentation feature. Go look… interesting! The gdata.InsertRow() method takes a dictionary, key and worksheet ID and does the rest on its own. Therefore… therefore… a list of dictionaries is what you need in order to populate a datagrid with more than 2 columns. And listodicts can be an optional parameter of booltab, in which case creating pre-populated worksheets becomes generic and built into the system.

Okay, so add the optional listodicts parameter to booltab, and double-check calls to the booltab function to ensure there’s no order dependent parameter gotcha’s. Okay, done. I now support an optional list in booltab. But now we need to do something with the list of dictionaries. Okay, I added that super-powerful line:

if listodicts: for onedict in listoticts: entry=gd.InsertRow(onedict, key, wsid)

…and in just that, so much is possible. Hmmmmm. How to test? Wow, just drop the scrapelist into a booltab directive. This is friggin’ awesome!

Ugh, got detoured again by gindexcount. The race to hit this stuff home by the end of the day derailed. Only so-so productive day. I still the the daily work journal helps keep me on track. I produced a whole PowerPoint today, albeit without graphics, on the future of SEO. I’m going to have to move it into a new template and spice it up with graphics for recording a course lesson for next week. But I have most of the thought-work done.

Can tomorrow truly be a Focus Friday? Can I complete the ezscrape functionality and move on? We will see.