Skip to content

Commit d464ee9

Browse files
committed
Add RemoteContentNode class to allow scripted curation of existing content
1 parent 6db33e5 commit d464ee9

File tree

7 files changed

+405
-80
lines changed

7 files changed

+405
-80
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,5 @@ video_cache_py3.sqlite
134134
.vim/
135135

136136
cache.sqlite
137+
138+
chefdata/
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/usr/bin/env python
2+
from ricecooker.chefs import SushiChef
3+
from ricecooker.classes.files import AudioFile
4+
from ricecooker.classes.files import DocumentFile
5+
from ricecooker.classes.licenses import get_license
6+
from ricecooker.classes.nodes import AudioNode
7+
from ricecooker.classes.nodes import DocumentNode
8+
from ricecooker.classes.nodes import RemoteContentNode
9+
from ricecooker.classes.nodes import TopicNode
10+
11+
"""
12+
This example shows how to use the RemoteContentNode to create a channel that
13+
curates content from another channel already on Studio into a new channel.
14+
"""
15+
16+
SOURCE_DOMAIN = "testdomain.org" ## change me!
17+
18+
original_channel_data = {
19+
"channel_id": None,
20+
"doc_node_id": None,
21+
"audio_node_id": None,
22+
}
23+
24+
25+
class OriginalChannelChef(SushiChef):
26+
channel_info = {
27+
"CHANNEL_TITLE": "Original channel",
28+
"CHANNEL_SOURCE_DOMAIN": SOURCE_DOMAIN,
29+
"CHANNEL_SOURCE_ID": "originalchannel",
30+
"CHANNEL_LANGUAGE": "en",
31+
}
32+
33+
def construct_channel(self, **kwargs):
34+
channel = self.get_channel(**kwargs)
35+
36+
document_node = DocumentNode(
37+
title="Growing potatoes",
38+
description="An article about growing potatoes on your rooftop.",
39+
source_id="pubs/mafri-potatoe",
40+
license=get_license("CC BY", copyright_holder="University of Alberta"),
41+
files=[
42+
DocumentFile(
43+
path="https://www.gov.mb.ca/inr/pdf/pubs/mafri-potatoe.pdf",
44+
language="en",
45+
)
46+
],
47+
)
48+
channel.add_child(document_node)
49+
50+
audio_node = AudioNode(
51+
source_id="also-sprach",
52+
title="Also Sprach Zarathustra",
53+
author="Kevin MacLeod / Richard Strauss",
54+
description="Also Sprach Zarathustra, Op. 30, is a tone poem by Richard Strauss, composed in 1896.",
55+
license=get_license("CC BY", copyright_holder="Kevin MacLeod"),
56+
files=[
57+
AudioFile(
58+
"https://ia600702.us.archive.org/33/items/Classical_Sampler-9615/Kevin_MacLeod_-_Also_Sprach_Zarathustra.mp3"
59+
)
60+
],
61+
)
62+
channel.add_child(audio_node)
63+
64+
return channel
65+
66+
67+
class CuratedChannelChef(SushiChef):
68+
channel_info = {
69+
"CHANNEL_TITLE": "Curated channel",
70+
"CHANNEL_SOURCE_DOMAIN": SOURCE_DOMAIN,
71+
"CHANNEL_SOURCE_ID": "curatedchannel",
72+
"CHANNEL_LANGUAGE": "en",
73+
}
74+
75+
def construct_channel(self, **kwargs):
76+
channel = self.get_channel(**kwargs)
77+
78+
document_topic = TopicNode(
79+
title="Documents",
80+
source_id="documents",
81+
)
82+
channel.add_child(document_topic)
83+
remote_document = RemoteContentNode(
84+
title="Glorious new title for the potato doc",
85+
source_channel_id=original_channel_data["channel_id"],
86+
source_node_id=original_channel_data["doc_node_id"],
87+
)
88+
document_topic.add_child(remote_document)
89+
90+
audio_topic = TopicNode(
91+
title="Audio",
92+
source_id="audio",
93+
)
94+
channel.add_child(audio_topic)
95+
remote_audio = RemoteContentNode(
96+
source_channel_id=original_channel_data["channel_id"],
97+
source_node_id=original_channel_data["audio_node_id"],
98+
)
99+
audio_topic.add_child(remote_audio)
100+
101+
return channel
102+
103+
104+
if __name__ == "__main__":
105+
"""
106+
Run this script on the command line using:
107+
python sushichef.py --token=YOURTOKENHERE9139139f3a23232
108+
"""
109+
original_chef = OriginalChannelChef()
110+
original_chef.main()
111+
original_channel = original_chef.construct_channel()
112+
113+
original_channel_data["channel_id"] = original_channel.get_node_id().hex
114+
original_channel_data["doc_node_id"] = (
115+
original_channel.children[0].get_node_id().hex
116+
)
117+
original_channel_data["audio_node_id"] = (
118+
original_channel.children[1].get_node_id().hex
119+
)
120+
121+
input(
122+
"Please visit the URL above and deploy the channel, and wait for it to finish. Then press enter to continue..."
123+
)
124+
125+
curated_chef = CuratedChannelChef()
126+
curated_chef.main()

0 commit comments

Comments
 (0)