forked from bstoilov/py3-pinterest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples.py
234 lines (154 loc) · 7.65 KB
/
examples.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
from py3pin.Pinterest import Pinterest
pinterest = Pinterest(email='email',
password='password',
username='username',
cred_root='cred_root')
# to release
# python3 setup.py sdist & twine upload --skip-existing dist/*
# proxies example:
# proxies = {"http":"http://username:password@proxy_ip:proxy_port"}
# Pinterest(email='emai', password='pass', username='name', cred_root='cred_root', proxies=proxies)
# login will obtain and store cookies for further use, they last around 15 days.
# NOTE: Since login will store the cookies in local file you don't need to call it more then 3-4 times a month.
# pinterest.login()
def get_user_profile():
return pinterest.get_user_overview(username='username')
def get_user_boards_batched(username=None):
boards = []
board_batch = pinterest.boards(username=username)
while len(board_batch) > 0:
boards += board_batch
board_batch = pinterest.boards(username=username)
return boards
def get_boards(username=None):
return pinterest.boards_all(username=username)
def get_board_pins_batched(board_id=''):
board_feed = []
feed_batch = pinterest.board_feed(board_id=board_id)
while len(feed_batch) > 0:
board_feed += feed_batch
feed_batch = pinterest.board_feed(board_id=board_id)
return board_feed
def delete_pin(pin_id=''):
# if pin doesn't exist or you have no rights to delete http 404 or 401 will be thrown
return pinterest.delete_pin(pin_id=pin_id)
def follow(user_id=''):
# even if you already follow this user a successful message is returned
return pinterest.follow_user(user_id=user_id)
def unfollow(user_id=''):
# even if you don't follow this user a successful message is returned
return pinterest.unfollow_user(user_id=user_id)
def get_following_batched(username=None, max_items=500):
# you can get following on any user, default is current user
# pinterest.get_following(username='some_user')
following = []
following_batch = pinterest.get_following(username=username)
while len(following_batch) > 0 and len(following) < max_items:
following += following_batch
following_batch = pinterest.get_following(username=username)
return following
def get_following(username=None):
# Gets full following list of a user
return pinterest.get_following_all(username=username)
def get_followers_batched(username=None, max_items=500):
followers = []
followers_batch = pinterest.get_user_followers(username=username)
while len(followers_batch) > 0 and len(followers) < max_items:
followers += followers_batch
followers_batch = pinterest.get_user_followers(username=username)
return followers
def get_followers(username=None):
# Gets a full list of user followers
return pinterest.get_user_followers_all(username=username)
def get_home_feed(max_items=100):
# This is what pinterest displays on your home page
# useful for auto repins
home_feed_pins = []
home_feed_batch = pinterest.home_feed()
while len(home_feed_batch) > 0 and len(home_feed_pins) < max_items:
home_feed_pins += home_feed_batch
home_feed_batch = pinterest.home_feed()
return home_feed_pins
def repin(pin_id='', board_id='', section_id=None):
return pinterest.repin(board_id=board_id, pin_id=pin_id, section_id=section_id)
def get_website_pinnable_images():
# Pinterest endpoint that gives all images on website
return pinterest.get_pinnable_images(url='https://www.tumblr.com/search/food')
def get_board_pin_recommendations(board_id='', max_items=100):
rec_pins = []
rec_batch = pinterest.board_recommendations(board_id=board_id)
while len(rec_batch) > 0 and len(rec_pins) < max_items:
rec_pins += rec_batch
return rec_pins
def pin(board_id='',
section_id=None,
image_url='https://i.pinimg.com/170x/32/78/bd/3278bd27073e1ec9c8a708409279768b.jpg',
description='this is auto pin',
title='a bot did this',
alt_text='alt text',
link='https://www.google.com/'):
return pinterest.pin(board_id=board_id, section_id=section_id, image_url=image_url,
alt_text=alt_text, description=description, title=title, link=link)
def upload_pin(board_id='',
section_id=None,
image_path='my_imag.png',
description='this is auto pin',
title='a bot did this',
link='https://www.google.com/'):
return pinterest.upload_pin(board_id=board_id, section_id=section_id, image_file=image_path,
description=description, title=title, link=link)
def search(max_items=100, scope='boards', query='food'):
# After change in pinterest API, you can no longer search for users
# Instead you need to search for something else and extract the user data from there.
# current pinterest scopes are: pins, buyable_pins, my_pins, videos, boards
results = []
search_batch = pinterest.search(scope=scope, query=query)
while len(search_batch) > 0 and len(results) < max_items:
results += search_batch
search_batch = pinterest.search(scope=scope, query=query)
return results
def follow_board(board_id=''):
return pinterest.follow_board(board_id=board_id)
def unfollow_board(board_id=''):
return pinterest.unfollow_board(board_id=board_id)
def invite(board_id='', target_user_id=''):
# If user is already invited to the board, you get 403 error.
return pinterest.invite(board_id=board_id, user_id=target_user_id)
def delete_invite(board_id='', target_user_id=''):
# If user is not invited to the board, you get 403 error.
return pinterest.delete_invite(board_id=board_id, invited_user_id=target_user_id)
def get_board_invites(board_id=''):
return pinterest.get_board_invites(board_id=board_id)
def comment_on_pin(pin_id='', comment_text='comment'):
# Forbidden and not found are thrown if you don't have permissions or comment does not exist
return pinterest.comment(pin_id=pin_id, text=comment_text)
def delete_comment(pin_id='', comment_id=''):
# Forbidden and not found are thrown if you don't have permissions or comment does not exist
return pinterest.delete_comment(pin_id=pin_id, comment_id=comment_id)
def get_pin_comments(pin_id=''):
return pinterest.get_comments(pin_id=pin_id)
def load_pin_by_id(pin_id=''):
return pinterest.load_pin(pin_id=pin_id)
# to pin/repin to section you just need to provide section id parameter to the respective function
# repin(board_id=board_id, section_id=section_id, pin_id='pin_id')
# pin(board_id=board_id, section_id=section_id)
# Careful with category names. They have different names than as shown on Pinterest
def create_board(name='',
description='',
category='other',
privacy='public',
layout='default'):
return pinterest.create_board(name=name, description=description, category=category,
privacy=privacy, layout=layout)
def create_board_section(board_id='', section_name=''):
return pinterest.create_board_section(board_id=board_id, section_name=section_name)
def delete_board_section(section_id=''):
return pinterest.delete_board_section(section_id=section_id)
def get_board_sections(board_id=''):
return pinterest.get_board_sections(board_id=board_id)
def get_board_section_feed(section_id=''):
return pinterest.get_section_pins(section_id=section_id)
def type_ahead(term="apple"):
return pinterest.type_ahead(term=term)
def add_pin_note(pin_id, note='test note'):
pinterest.add_pin_note(pin_id=pin_id, note=note)