-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
77 lines (66 loc) · 2.13 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import config
from kontent_delivery.client import DeliveryClient
from samples.custom_item_resolver import CustomItemResolver
from samples.custom_link_resolver import CustomLinkResolver
from kontent_delivery.builders.filter_builder import Filter
from kontent_delivery.builders.image_builder import ImageBuilder
# MANUAL TESTS
client = DeliveryClient(config.project_id, options=config.delivery_options)
client.custom_link_resolver = CustomLinkResolver()
client.custom_item_resolver = CustomItemResolver()
# ITEMS
r = client.get_content_items(
Filter("system.type", "[eq]", "coffee"),
Filter("elements.price", "[range]", "10.5,50"),
Filter("", "depth", 6)
)
# RESULTS
for item in r.items:
print(item.name)
print(r.api_response.url)
# ITEM
r2 = client.get_content_item("coffee_processing_techniques")
# r2 = client.get_content_item("brisbane") # draft item for preview test
# RESULTS
print(r2.codename)
# TEXT
print(r2.elements.title.value)
# MULTICHOICE
print(r2.elements.radio_choices.value[0].codename)
for check in r2.elements.checkbox_choices.value:
print(check.codename)
# TAXONOMY
for persona in r2.elements.personas.value:
print(persona.name)
# ASSET
asset_url = r2.elements.teaser_image.value[0].url
print(r2.elements.teaser_image.value[0].url)
image = ImageBuilder(asset_url)
transformed_image = image.transform(
image.width(300),
image.height(300),
image.pixel_ratio(1.5),
image.fit_mode("crop"),
image.rect(100, 100, 0.7, 0.7),
image.focal_point(0.2, 0.7, 5),
image.background_color("7A0099EE"),
image.output_format("webp"),
image.quality(85),
image.lossless(True),
image.auto_format_selection(False)
)
print(transformed_image)
# LINKED_ITEMS
print(r2.elements.related_articles.value)
print(r2.get_linked_items("related_articles"))
for item in r2.get_linked_items("related_articles"):
print(f"name: {item.name} summary: {item.elements.summary.value}")
# RICH TEXT VALUES
print(r2.elements.body_copy.value)
# ITEMS FEED
r = client.get_content_items_feed()
while r.next:
next_result = r.get_next()
r.feed.items.extend(next_result.items)
for item in r.feed.items:
print(item.name)