ricecooker quick startThis mini-tutorial will walk you through the steps of running a simple chef script SimpleChef that uses the ricecooker framework to upload a content channel to the Kolibri Studio server.
We'll go over the same steps as described in the usage, but this time showing the expected output of each step.
To follow along and run the code in this notebook, you'll need to clone the ricecooker repository, crate a virtual environement, install ricecooker using pip install ricecooker, install Jypyter notebook using pip install jupyter, then start the jupyter notebook server by running jupyter notebook. You will then be able to run all the code sections in this notebook and poke around.
You will need a` Studio Authorization Token to create a channel on Kolibri Studio. In order to obtain such a token:
You must pass the token on the command line as --token=<your-auth-token> when
calling your chef script. Alternatively, you can create a file to store your token
and pass in the command line argument --token="path/to/file.txt".
We'll use following simple chef script as an the running example in this section.
You can find the full source code of it examples/simple_chef.py.
Mmmm, potato... potato give you power!
In [1]:
#!/usr/bin/env python
from ricecooker.chefs import SushiChef
from ricecooker.classes.nodes import ChannelNode, TopicNode, DocumentNode
from ricecooker.classes.files import DocumentFile
from ricecooker.classes.licenses import get_license
class SimpleChef(SushiChef):
channel_info = {
'CHANNEL_TITLE': 'Potatoes info channel',
'CHANNEL_SOURCE_DOMAIN': '<yourdomain.org>', # where you got the content
'CHANNEL_SOURCE_ID': '<unique id for channel>', # channel's unique id
'CHANNEL_LANGUAGE': 'en', # le_utils language code
'CHANNEL_THUMBNAIL': 'https://upload.wikimedia.org/wikipedia/commons/b/b7/A_Grande_Batata.jpg', # (optional)
'CHANNEL_DESCRIPTION': 'What is this channel about?', # (optional)
}
def construct_channel(self, **kwargs):
channel = self.get_channel(**kwargs)
potato_topic = TopicNode(title="Potatoes!", source_id="<potatos_id>")
channel.add_child(potato_topic)
doc_node = DocumentNode(
title='Growing potatoes',
description='An article about growing potatoes on your rooftop.',
source_id='pubs/mafri-potatoe',
license=get_license('CC BY', copyright_holder='University of Alberta'),
language='en',
files=[DocumentFile(path='https://www.gov.mb.ca/inr/pdf/pubs/mafri-potatoe.pdf',
language='en')],
)
potato_topic.add_child(doc_node)
return channel
if __name__ == '__main__':
"""
Run this script on the command line using:
python simple_chef.py -v --reset --token=YOURTOKENHERE9139139f3a23232
"""
simple_chef = SimpleChef()
simple_chef.main()
Note: make sure you change the values of CHANNEL_SOURCE_DOMAIN and CHANNEL_SOURCE_ID
before you try running this script. The combination of these two values is used
to compute the channel_id for the Kolibri channel you're creating. If you keep
the lines above unchanged, you'll get an error because the channel with source
domain 'gov.mb.ca' and source id 'website_docs' already exists on Kolibri Studio.
Run of chef script by calling it on the command line:
In [9]:
!cd ../../examples; python simple_chef.py -v --reset --token=$STUDIO_TOKEN
In [ ]:
Now that you have a working example of a simple chef you can extend it by adding more content types.
In [ ]: