adrianpierce commited on
Commit
cd742a5
·
1 Parent(s): 9e3f6c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -42
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
- with st.form("get_recipes"):
13
- st.title('Get Recipes:')
14
- n_recipes = st.slider('Select number of recipes to get', 0, 20, 10)
15
- submitted = st.form_submit_button("Get")
16
- if submitted:
17
- url = "https://api.notion.com/v1/databases/180f4b492f4d421c88028c54cfe077a5/query"
18
- payload = json.dumps({
19
- "filter": {
20
- "property": "Weekly Rotation",
21
- "checkbox": {
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
- response = requests.request("POST", url, headers=headers, data=payload)
32
- recipes = response.json()
33
-
34
- recipe_list = []
35
- for recipe in random.sample(recipes['results'], n_recipes):
36
- recipe_dict = {}
37
- recipe_dict['name'] = recipe["properties"]["Name"]["title"][0]["plain_text"].strip()
38
- recipe_dict['url'] = recipe["url"]
39
- recipe_list.append(recipe_dict)
40
-
41
- st.session_state.df = pd.DataFrame.from_dict(recipe_list)
42
- st.session_state.df.insert(1,'Save',[False]*len(st.session_state.df))
43
- st.session_state.edited_df = st.data_editor(
44
- st.session_state.df,
45
- column_config={"url": st.column_config.LinkColumn()},
46
- disabled=["name", "url"],
47
- hide_index=True,
48
- )
 
 
 
 
 
 
 
 
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
 
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: