Created
January 25, 2016 09:06
-
-
Save leplatrem/a2d95b660820686eea35 to your computer and use it in GitHub Desktop.
Import json records in Kinto
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
import json | |
import uuid | |
from kinto_client import Client | |
client = Client(server_url="https://kinto-leplatrem.herokuapp.com/v1", | |
auth=('admin', 'password')) | |
client.create_bucket('guessign', safe=False) | |
try: | |
client.delete_collection('it', bucket='guessign') | |
except: | |
pass | |
client.create_collection('it', bucket='guessign', permissions={"read": ["system.Everyone"]}, safe=False) | |
# Comes from here: | |
# https://github.com/leplatrem/guessign/tree/gh-pages/data | |
f = open("../../../Perso/guessign/data/it.json", "r") | |
records = json.load(f) | |
f.close() | |
with client.batch(bucket='guessign', collection='it') as batch: | |
for record in records: | |
record['id'] = str(uuid.uuid4()) | |
batch.create_record(data=record) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment