Spaces:
Sleeping
Sleeping
Commit
·
cd742a5
1
Parent(s):
9e3f6c4
Update app.py
Browse files
app.py
CHANGED
@@ -9,51 +9,50 @@ if 'df' not in st.session_state:
|
|
9 |
st.session_state.df_edited = st.session_state.df.copy()
|
10 |
st.session_state.df2 = pd.DataFrame()
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
"equals": True
|
23 |
-
}
|
24 |
-
}
|
25 |
-
})
|
26 |
-
headers = {
|
27 |
-
'Authorization': st.secrets["notion_authorization"],
|
28 |
-
'Content-Type': 'application/json',
|
29 |
-
'Notion-Version': '2022-02-22'
|
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 |
-
st.button(label='Save Recipes', on_click=save_recipes)
|
56 |
|
|
|
57 |
|
58 |
st.title('Saved Recipes:')
|
59 |
if len(st.session_state.df2) == 0:
|
|
|
9 |
st.session_state.df_edited = st.session_state.df.copy()
|
10 |
st.session_state.df2 = pd.DataFrame()
|
11 |
|
12 |
+
st.title('Get Recipes:')
|
13 |
+
n_recipes = st.slider('Select number of recipes to get', 0, 20, 10)
|
14 |
+
|
15 |
+
def get_recipes():
|
16 |
+
url = "https://api.notion.com/v1/databases/180f4b492f4d421c88028c54cfe077a5/query"
|
17 |
+
payload = json.dumps({
|
18 |
+
"filter": {
|
19 |
+
"property": "Weekly Rotation",
|
20 |
+
"checkbox": {
|
21 |
+
"equals": True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
}
|
23 |
+
}
|
24 |
+
})
|
25 |
+
headers = {
|
26 |
+
'Authorization': st.secrets["notion_authorization"],
|
27 |
+
'Content-Type': 'application/json',
|
28 |
+
'Notion-Version': '2022-02-22'
|
29 |
+
}
|
30 |
+
response = requests.request("POST", url, headers=headers, data=payload)
|
31 |
+
recipes = response.json()
|
32 |
+
|
33 |
+
recipe_list = []
|
34 |
+
for recipe in random.sample(recipes['results'], n_recipes):
|
35 |
+
recipe_dict = {}
|
36 |
+
recipe_dict['name'] = recipe["properties"]["Name"]["title"][0]["plain_text"].strip()
|
37 |
+
recipe_dict['url'] = recipe["url"]
|
38 |
+
recipe_list.append(recipe_dict)
|
39 |
+
|
40 |
+
st.session_state.df = pd.DataFrame.from_dict(recipe_list)
|
41 |
+
st.session_state.df.insert(1,'Save',[False]*len(st.session_state.df))
|
42 |
+
st.session_state.edited_df = st.data_editor(
|
43 |
+
st.session_state.df,
|
44 |
+
column_config={"url": st.column_config.LinkColumn()},
|
45 |
+
disabled=["name", "url"],
|
46 |
+
hide_index=True,
|
47 |
+
)
|
48 |
+
st.button(label='Get', on_click=get_recipes)
|
49 |
|
50 |
+
def save_recipes():
|
51 |
+
filter_1 = st.session_state.df_edited['Values'] == True
|
52 |
+
filtered = st.session_state.df_edited[filter_1]
|
53 |
+
st.session_state.df2 = pd.concat([st.session_state.df2, filtered])
|
|
|
|
|
54 |
|
55 |
+
st.button(label='Save Recipes', on_click=save_recipes)
|
56 |
|
57 |
st.title('Saved Recipes:')
|
58 |
if len(st.session_state.df2) == 0:
|