Spaces:
Sleeping
Sleeping
import requests | |
import json | |
import random | |
import pandas as pd | |
import streamlit as st | |
with st.form("my_form"): | |
n_recipes = st.slider('Select number of recipes to get', 0, 20, 1) | |
submitted = st.form_submit_button("Submit") | |
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() | |
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, | |
) |