-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathreadwise.py
More file actions
47 lines (41 loc) · 1.73 KB
/
Copy pathreadwise.py
File metadata and controls
47 lines (41 loc) · 1.73 KB
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
import requests,sys
#proxies = {'http':'http://127.0.0.1:8080','https':'http://127.0.0.1:8080'}
class ReadWise:
def __init__(self, token):
self.token = token
def check_token(self):
r = requests.get(url="https://readwise.io/api/v2/auth/",headers={"Authorization": "Token %s" % self.token})
if r.status_code != 204:
sys.exit("[+] Readwise token is outdated. Cannot continue working.")
def highlight(self, **kwargs):
# if smth is empty in the telegram post send empty string to Readwise
for v in kwargs.values():
if v is None:
v = ""
r = requests.post(url="https://readwise.io/api/v2/highlights/",headers={"Authorization": "Token %s" % self.token},
json={"highlights": [
{
"text": kwargs.get("text"),
"title": kwargs.get("title"),
"source_url": kwargs.get("source_url"),
"source_type": "telewise_bot",
"note": kwargs.get("note"),
"highlighted_at": kwargs.get("highlighted_at")
}
]}
)
def save(self, **kwargs):
# if smth is empty in the telegram post send empty string to Readwise
for v in kwargs.values():
if v is None:
v = ""
r = requests.post(url="https://readwise.io/api/v3/save/",headers={"Authorization": "Token %s" % self.token},
json=
{
"url": kwargs.get("url"),
"html": kwargs.get("html"),
"title": kwargs.get("title"),
"summary": kwargs.get("summary"),
"should_clean_html": "true"
}
)