Skip to content

Instantly share code, notes, and snippets.

@plashchynski
Created June 12, 2016 00:00
Show Gist options
  • Select an option

  • Save plashchynski/5fe78b225a06db5d7f09621f97b984d5 to your computer and use it in GitHub Desktop.

Select an option

Save plashchynski/5fe78b225a06db5d7f09621f97b984d5 to your computer and use it in GitHub Desktop.
Convert google cloud store backup to CSV
import sys
import csv
import codecs
sys.path.append('/usr/local/google_appengine')
from google.appengine.api.files import records
from google.appengine.datastore import entity_pb
from google.appengine.api import datastore
encoder = codecs.getincrementalencoder("utf-8")()
for i in range(0, 255):
print("output-%d..." % i)
raw = open(("output-%d" % i), 'r')
reader = records.RecordsReader(raw)
with open(('output-%d.csv' % i), 'wb') as csvfile:
csvwriter = csv.writer(csvfile)
for record in reader:
entity_proto = entity_pb.EntityProto(contents=record)
entity = datastore.Entity.FromPb(entity_proto)
field2 = entity['field2'].encode("utf-8")
csvwriter.writerow([entity['field1'], field2, entity['field3'], entity['field4']])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment