-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipedream_python.py
72 lines (66 loc) · 2.71 KB
/
pipedream_python.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
64
65
66
67
68
69
70
71
72
import requests
from notion_client import Client
import json
import re
from pocket import Pocket
def handler(pd: "pipedream"):#extract url from pocket.json
def url():
extracted_url = pd.steps["trigger"]["event"]["given_url"]
return extracted_url
#------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
def name():#extract name from pocket.json
name = pd.steps["trigger"]["event"]["resolved_title"]
name = re.sub(r'\#\w+', '', name)
name = name[:100]
return name
#------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
def get_tags():#extract tags from pocket api call because pipedreams call doesn't return tags because of detailType not being "complete"
consumer_key = "your-consumer-key"
access_token = "your-access-token"
pocket_instance = Pocket(consumer_key, access_token=access_token)
response = pocket_instance.get(detailType="complete")
new_tuple = response[:1]
for e in new_tuple[0]["list"]:
if e == pd.steps["trigger"]["event"]["item_id"]:
tags = new_tuple[0]["list"][e]["tags"]
tags_list = [{"name": tag} for tag in tags]
return tags_list
#------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
def db_id_set(extracted_url):#set database id depending on type of saved content
if "insta" in extracted_url:
db_id = "your insta database-id"
elif "reddit" in extracted_url:
db_id = "your reddit database-id"
elif "youtube" in extracted_url:
db_id = "your youtube database-id"
else:
db_id = "your article database-id"
return db_id
#------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
token = pd.inputs["notion"]["$auth"]["oauth_access_token"]
extracted_url = url()
db_id = db_id_set((extracted_url))
notion = Client(auth=token)
title = name()
tags = get_tags()
new_page = {
"URL": {
"type": "url",
"url": extracted_url
},
"Tags": {
"type": "multi_select",
"multi_select": tags
},
"Titel": {
"type": "title",
"title": [
{
"text": {
"content": title
}
}
]
}
}
notion.pages.create(parent={"database_id": db_id}, properties=new_page)