Import a CSV to Google Fusion Table with python -


from http://fuzzytolerance.info/blog/2012/01/13/2012-01-14-updating-google-fusion-table-from-a-csv-file-using-python/ have edited code import necessary modules, following error "attributeerror: 'module' object has no attribute 'urlencode'". run code , prompted enter password, enter own google account password, , code gives me error message, pehaps need define password somewhere?

i wonder if can please trouble shoot code or advise me on how avoid error or advise me of easier way import csv google fusion table own

here code

import csv  decimal import *  import getpass  fusiontables.authorization.clientlogin import clientlogin  fusiontables import ftclient  nameagenick = 'c:\\users\\user\\desktop\\nameagenickname.txt'  # check see if integer  def isint(s):      try:          int(s)          return true      except valueerror:          return false    # check see if float  def isfloat(s):      try:          float(s)          return true      except valueerror:          return false      # open csv file  ifile  = open(nameagenick, "rb")  reader = csv.reader(ifile)    # gft table id  tableid = "tableid"  # username  username = "username"  # prompt password - can hardcode more secure  password = getpass.getpass("enter password:")    # token , connect gft  token = clientlogin().authorize(username, password)  ft_client = ftclient.clientloginftclient(token)      # loop through csv data , upload  # assumptions data: if it's float less 0, it's percentage  # floats being rounded 1 significant digit  # non-numbers wrapped in single quote string-type in updatate statement  # first row column names , matches column names in fustion tables  # first column unique id i'll use select record updating in fusion tables  rownum = 0  setlist = list()  nid = 0  row in reader:      # save header row.      if rownum == 0:          header = row      else:          colnum = 0          setlist[:] = []          col in row:              thedata = col              # bit rounds numbers , turns numbers < 1 percentages              if isfloat(thedata):                  if isint(thedata) false:                      if float(thedata) < 1:                          thedata = float(thedata) * 100                      thedata = round(float(thedata), 1)              else:                  thedata = "'" + thedata + "'"              # make sql clause row              setlist.append(header[colnum] + "=" + str(thedata))              nid = row[0]              colnum += 1          # rowid , update record          rowid = ft_client.query("select rowid " + tableid + " id = " + nid).split("\n")[1]          print( rowid)          print( ft_client.query("update " + tableid + " set " + ",".join(map(str, setlist)) + " rowid = '" + rowid + "'"))      rownum += 1    ifile.close()​

and module error occurs:

#!/usr/bin/python  #  # copyright (c) 2010 google inc.    """ clientlogin.  """    __author__ = 'kbrisbin@google.com (kathryn brisbin)'    import urllib, urllib2    class clientlogin():    def authorize(self, username, password):      auth_uri = 'https://www.google.com/accounts/clientlogin'      authreq_data = urllib.urlencode({ //////here error          'email': username,          'passwd': password,          'service': 'fusiontables',          'accounttype': 'hosted_or_google'})      auth_req = urllib2.request(auth_uri, data=authreq_data)      auth_resp = urllib2.urlopen(auth_req)      auth_resp_body = auth_resp.read()        auth_resp_dict = dict(          x.split('=') x in auth_resp_body.split('\n') if x)      return auth_resp_dict['auth']  ​


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -