使用Python阅读Google电子表格,并将值与文本文件进行比较

时间:2013-02-13 15:08:10

标签: python

我有一个包含域列表的Google电子表格,我还有一个文本文件中的域列表。我想使用Google API for Python打开电子表格,并检查文本文件中是否存在域名,如果未设置值0,则在单元格中设置标志值为1。

到目前为止,我有这段代码:

feed = gdataclient.GetListFeed(spreadsheet_key,
                                       worksheet_id)
row = 2
  #column index=12 corresponds to column name 'validdomain'
  col = 11
  domains = [domain.strip() for domain in open(domains_file,'r')]
  for row_entry in feed.entry:
    record = text_db.Record(row_entry=row_entry)
    if record.content['domainname'] in domains:
      gdataclient.UpdateCell(row = row,
                                 col = col,
                                 inputValue = '1' ,
                                 key = spreadsheet_key,
                                 wksht_id = worksheet_id)
    else:
      gdataclient.UpdateCell(row = row,
                                 col = col,
                                 inputValue = '0' ,
                                 key = spreadsheet_key,
                                 wksht_id = worksheet_id)
    row += 1 

由于电子表格很大,因此此代码可以暂时超时。

0 个答案:

没有答案