-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
63 lines (54 loc) · 1.79 KB
/
helpers.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import requests, json, urllib.request
from flask import render_template
from bs4 import BeautifulSoup
def apology(message, code=400):
"""Render message as an apology to user."""
def escape(s):
"""
Escape special characters.
https://github.com/jacebrowning/memegen#special-characters
"""
for old, new in [("-", "--"), (" ", "-"), ("_", "__"), ("?", "~q"),
("%", "~p"), ("#", "~h"), ("/", "~s"), ("\"", "''")]:
s = s.replace(old, new)
return s
return render_template("apology.html", top=code, bottom=escape(message)), code
def createPage(databaseId, headers, titleInput, ingredientsInput, urlInput):
createUrl = 'https://api.notion.com/v1/pages'
newPageData = {
"parent": {"database_id": databaseId},
"properties": {
"Name": {
"title": [
{
"type": "text",
"text": {
"content": titleInput
}
}
]
},
"Ingredients": {
"rich_text": [
{
"type": "text",
"text": {
"content": ingredientsInput
}
},
]
},
"Link": {
"url": urlInput
}
}
}
data = json.dumps(newPageData)
res = requests.request("POST", createUrl, headers=headers, data=data)
return res.status_code
def getImage (urlInput):
page = urllib.request.urlopen(urlInput)
soup = BeautifulSoup(page, features="html.parser")
image = soup.find_all('img')
img = image[2]['src']
return img