forked from guilhermesdev/directus-flask-example
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
directus.py
31 lines (21 loc) · 820 Bytes
/
directus.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
import requests
import os
DIRECTUS_BASE_URL = os.environ.get("DIRECTUS_BASE_URL")
def get_global_data():
response = requests.get(f"{DIRECTUS_BASE_URL}/items/global")
return response.json().get("data")
def get_page_by_slug(slug):
response = requests.get(f"{DIRECTUS_BASE_URL}/items/pages/{slug}")
return response.json().get("data")
def get_posts():
response = requests.get(
f"{DIRECTUS_BASE_URL}/items/posts?fields=slug,title,description,publish_date,author.name&sort=-publish_date"
)
return response.json().get("data")
def get_post_by_slug(slug):
response = requests.get(
f"{DIRECTUS_BASE_URL}/items/posts/{slug}?fields=*,author.name"
)
post = response.json().get("data")
post["image"] = f'{DIRECTUS_BASE_URL}/assets/{post["image"]}'
return post