Skip to content

Instantly share code, notes, and snippets.

@blainegarrett
Created April 23, 2018 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blainegarrett/b2526c81572b0f231abc7df4fc02cd78 to your computer and use it in GitHub Desktop.
Save blainegarrett/b2526c81572b0f231abc7df4fc02cd78 to your computer and use it in GitHub Desktop.
Remote Console Script to Dump Pref Data to CSV
# Generate a csv of the prefs data
# In the ./app dir execute: remote_api_shell.py -s pref-service.appspot.com
import csv
from api.entities import PreferenceEntity
from rest_core.utils import get_resource_id_from_key
q = PreferenceEntity.query()
cursor = None
more = True
total = 0
with open('../prefdataBIG.csv', 'wb') as csvfile:
writer = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
# Write the headers
writer.writerow(('resource_id', 'user_id', 'item_id', 'pref', 'synced_timestamp', 'timestamp'))
while(more):
entities, cursor, more = q.fetch_page(1000, start_cursor=cursor)
for e in entities:
writer.writerow((get_resource_id_from_key(e.key), e.user_id, e.item_id, e.pref, e.synced_timestamp, e.timestamp))
total = total + 1
print "Writing batch %s " % total
print "Done..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment