Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fusion tables importrows

Have anyone used the function importRows() from fusion table API? As the API reference below, https://developers.google.com/fusiontables/docs/v1/reference/table/importRows I have to supply CSV data in the request body. But what should I do for the html body exactly?

My code:

http = getAuthorizedHttp()

DISCOVERYURL = 'https://www.googleapis.com/discovery/v1/apis/{api}/{apiVersion}/rest'

ftable = build('fusiontables', 'v1', discoveryServiceUrl=DISCOVERYURL, http=http)

body = create_ft(CSVFILE,"title here")   # the function to load csv file and create the table with columns from csv file.
result = ftable.table().insert(body=body).execute()
print result["tableId"]   # good, I have got the id for new created table

# I have no idea how to go on here..
f = ftable.table().importRows(tableId=result["tableId"])
f.body = ?????????????
f.execute()
like image 770
timchen Avatar asked Nov 20 '25 22:11

timchen


2 Answers

I finally fixed my problem, my code can be found in the following link. https://github.com/childnotfound/parser/blob/master/uploader.py

like image 114
timchen Avatar answered Nov 22 '25 12:11

timchen


I fixed the problem like this:

media = http.MediaFileUpload('example.csv',  mimetype='application/octet-stream', resumable=True)
request = service.table().importRows(media_body=media, tableId='1cowubQ0vj_H9q3owo1vLM_gMyavvbuoNmRQaYiZV').execute()
like image 35
maldewar Avatar answered Nov 22 '25 12:11

maldewar