-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
55 lines (39 loc) · 1.11 KB
/
main.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
#Imports
from notion.client import NotionClient
import random
import smtplib
import requests
#Create array of entries
all_entries = []
#Set up notion client
#replace your_token with a valid notion v2 token - can be found in cookies
client = NotionClient(token_v2="your_token")
#Get table from notion
#replace your_page_url with the url of a notion page containing a table
cv = client.get_collection_view("your_page_url")
#Add text of each row to entries array
for row in cv.collection.get_rows():
all_entries.append(row.title)
#Display random sample of 3 entries for testing
random_sample = random.sample(all_entries, 3)
test = ""
for entry in random_sample:
test = test + entry + "\n" + "\n"
print(test)
#Send to Readwise
#Replace XXX with your Readwise token
token = "Token XXX"
for entry in all_entries:
data = {
"highlights": [{
"text": entry,
"title": "Thoughts",
"author": "Me",
"source_type": "book",
}]
}
requests.post(
url="https://readwise.io/api/v2/highlights/",
headers={"Authorization": token},
json= data
)