adrianpierce commited on
Commit
726778d
·
1 Parent(s): dc19f53

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -30
app.py CHANGED
@@ -4,34 +4,36 @@ import random
4
  import pandas as pd
5
  import streamlit as st
6
 
7
- url = "https://api.notion.com/v1/databases/180f4b492f4d421c88028c54cfe077a5/query"
8
-
9
- payload = json.dumps({
10
- "filter": {
11
- "property": "Weekly Rotation",
12
- "checkbox": {
13
- "equals": True
 
 
 
 
 
 
 
 
 
14
  }
15
- }
16
- })
17
- headers = {
18
- 'Authorization': 'Bearer secret_oG3PIzAL10np4NadmID4X93ISNJP7zHBr6CQ8Oskakb',
19
- 'Content-Type': 'application/json',
20
- 'Notion-Version': '2022-02-22'
21
- }
22
- response = requests.request("POST", url, headers=headers, data=payload)
23
- recipes = response.json()
24
- n_recipes = st.slider('Select number of recipes to get', 0, 20, 1)
25
- recipe_list = []
26
- for recipe in random.sample(recipes['results'], n_recipes):
27
- recipe_dict = {}
28
- recipe_dict['name'] = recipe["properties"]["Name"]["title"][0]["plain_text"].strip()
29
- recipe_dict['url'] = recipe["url"]
30
- recipe_list.append(recipe_dict)
31
-
32
- df = pd.DataFrame.from_dict(recipe_list)
33
- st.dataframe(
34
- df,
35
- column_config={"url": st.column_config.LinkColumn()},
36
- hide_index=True,
37
- )
 
4
  import pandas as pd
5
  import streamlit as st
6
 
7
+ with st.form("my_form"):
8
+ n_recipes = st.slider('Select number of recipes to get', 0, 20, 1)
9
+ submitted = st.form_submit_button("Submit")
10
+ url = "https://api.notion.com/v1/databases/180f4b492f4d421c88028c54cfe077a5/query"
11
+ payload = json.dumps({
12
+ "filter": {
13
+ "property": "Weekly Rotation",
14
+ "checkbox": {
15
+ "equals": True
16
+ }
17
+ }
18
+ })
19
+ headers = {
20
+ 'Authorization': 'Bearer secret_oG3PIzAL10np4NadmID4X93ISNJP7zHBr6CQ8Oskakb',
21
+ 'Content-Type': 'application/json',
22
+ 'Notion-Version': '2022-02-22'
23
  }
24
+ response = requests.request("POST", url, headers=headers, data=payload)
25
+ recipes = response.json()
26
+
27
+ recipe_list = []
28
+ for recipe in random.sample(recipes['results'], n_recipes):
29
+ recipe_dict = {}
30
+ recipe_dict['name'] = recipe["properties"]["Name"]["title"][0]["plain_text"].strip()
31
+ recipe_dict['url'] = recipe["url"]
32
+ recipe_list.append(recipe_dict)
33
+
34
+ df = pd.DataFrame.from_dict(recipe_list)
35
+ st.dataframe(
36
+ df,
37
+ column_config={"url": st.column_config.LinkColumn()},
38
+ hide_index=True,
39
+ )