Skip to content

Instantly share code, notes, and snippets.

@leplatrem
Created January 25, 2016 09:06
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 leplatrem/a2d95b660820686eea35 to your computer and use it in GitHub Desktop.
Save leplatrem/a2d95b660820686eea35 to your computer and use it in GitHub Desktop.
Import json records in Kinto
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