-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathlea.py
More file actions
106 lines (88 loc) · 2.52 KB
/
Copy pathlea.py
File metadata and controls
106 lines (88 loc) · 2.52 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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python3
# Wrapper for Leanote API v1
import requests as req
LEANOTE_API_BASE = 'https://leanote.com/api'
token = ''
def login(email, pwd):
"""Login in Leanote.
Args:
email: Email of your account.
pwd: Password of your account.
Returns:
A string represents your login token, empty if login failed.
"""
payload = {
'email': email,
'pwd': pwd,
}
r = req.get(LEANOTE_API_BASE + '/auth/login', params=payload)
if r.status_code != req.codes.ok:
print('Login fail, please try again.')
data = r.json()
print('Login success, welcome %s (%s).' %(data['Username'], data['Email']))
global token
token = data['Token']
def get_notebooks():
"""Get notebooks of logined account.
Returns:
A list that contains notebooks' info.
"""
payload = {
'token': token,
}
r = req.get(LEANOTE_API_BASE + '/notebook/getNotebooks', params=payload)
if r.status_code != req.codes.ok:
print('Failed to get notebooks, please try again.')
return ''
data = r.json()
return data
def get_notes(nb_id):
"""Get notes of notebook @nb_id
Args:
nb_id: Id of notebook.
Returns:
A list that contains notes' info.
"""
payload = {
'token': token,
'notebookId': nb_id,
}
r = req.get(LEANOTE_API_BASE + '/note/getNotes', params=payload)
if r.status_code != req.codes.ok:
print('Failed to get notes, please try again.')
return ''
data = r.json()
return data
def get_note(note_id):
"""Get note and its content.
Args:
note_id: Id of note.
Returns:
Note that contains meta-info and content.
"""
payload = {
'token': token,
'noteId': note_id,
}
r = req.get(LEANOTE_API_BASE + '/note/getNoteAndContent', params=payload)
if r.status_code != req.codes.ok:
print('Failed to get note, please try again.')
return ''
data = r.json()
return data
def get_image(image_id):
"""Get image by @image_id.
Args:
image_id: Id of image.
Returns:
Image bytes
"""
payload = {
'token': token,
'fileId': image_id,
}
r = req.get(LEANOTE_API_BASE + '/file/getImage', params=payload)
if r.status_code != req.codes.ok:
print('Failed to get image, please try again.')
return ''
return r.content