SHARE
TWEET

Untitled

a guest Jul 11th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys, os, json
  2. import datetime
  3.  
  4. sys.path.append(os.path.expanduser('~/google-cloud-sdk/platform/google_appengine/'))
  5. from google.appengine.api.files import records
  6. from google.appengine.datastore import entity_pb
  7. from google.appengine.api import datastore
  8.  
  9. def myconverter(o):
  10.     if isinstance(o, datetime.datetime):
  11.         return o.isoformat()
  12.  
  13. for path, dirs, files in os.walk('./'):
  14.  
  15.     for fn in files:
  16.         f = os.path.join(path, fn)
  17.         if not fn.startswith('output'):
  18.             continue
  19.  
  20.         with open(f, 'r') as raw:
  21.  
  22.             reader = records.RecordsReader(raw)
  23.  
  24.             for record in reader:
  25.                 entity_proto = entity_pb.EntityProto(contents=record)
  26.                 entity = datastore.Entity.FromPb(entity_proto)
  27.                 entity['table'] = path[2:]
  28.                 j = json.dumps(entity, default=myconverter)
  29.                 print (j)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top