Created
April 23, 2018 16:32
-
-
Save blainegarrett/b2526c81572b0f231abc7df4fc02cd78 to your computer and use it in GitHub Desktop.
Remote Console Script to Dump Pref Data to CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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