File size: 1,030 Bytes
ce889fc
 
 
4ef3b48
6745377
ce889fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dc19f53
4ef3b48
ce889fc
4ef3b48
 
 
 
 
 
d0d1e70
 
 
 
 
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
import requests
import json
import random
import pandas as pd
import streamlit as st

url = "https://api.notion.com/v1/databases/180f4b492f4d421c88028c54cfe077a5/query"

payload = json.dumps({
  "filter": {
    "property": "Weekly Rotation",
    "checkbox": {
      "equals": True
    }
  }
})
headers = {
  'Authorization': 'Bearer secret_oG3PIzAL10np4NadmID4X93ISNJP7zHBr6CQ8Oskakb',
  'Content-Type': 'application/json',
  'Notion-Version': '2022-02-22'
}
response = requests.request("POST", url, headers=headers, data=payload)
recipes = response.json()
n_recipes = st.slider('Select number of recipes to get', 0, 20, 1)
recipe_list = []
for recipe in random.sample(recipes['results'], n_recipes):
    recipe_dict = {}
    recipe_dict['name'] = recipe["properties"]["Name"]["title"][0]["plain_text"].strip()
    recipe_dict['url'] = recipe["url"]
    recipe_list.append(recipe_dict)

df = pd.DataFrame.from_dict(recipe_list)
st.dataframe(
    df,
    column_config={"url": st.column_config.LinkColumn()},
    hide_index=True,
)