forked from bstoilov/py3-pinterest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
follow_examples.py
63 lines (49 loc) · 1.88 KB
/
follow_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
from py3pin.Pinterest import Pinterest
username = 'username'
password = 'password!'
email = 'email'
# cred_root is the place the user sessions and cookies will be stored you should specify this to avoid permission issues
cred_root = 'cred_root'
pinterest = Pinterest(email=email,
password=password,
username=username,
cred_root=cred_root)
def search_boards():
results = []
max_results = 100
batch_size = 50
query = 'food'
scope = 'boards'
# Obtain a list of boards we want to follow
search_batch = pinterest.search(scope=scope, query=query, page_size=batch_size)
while len(search_batch) > 0 and len(results) < max_results:
results += search_batch
pinterest.search(scope=scope, query=query, page_size=batch_size)
return results
def search_users():
# pinterest no longer allows to search for users, we will search for pins and extract the pinners
results = []
max_results = 100
batch_size = 50
query = 'food'
scope = 'pins'
# Obtain a list of boards we want to follow
search_batch = pinterest.search(scope=scope, query=query, page_size=batch_size)
while len(search_batch) > 0 and len(results) < max_results:
for res in search_batch:
if 'pinner' in res:
results.append(res['pinner'])
search_batch = pinterest.search(scope=scope, query=query, page_size=batch_size)
return results
boards = search_boards()
# Follow boards
for b in boards:
print(b['url'])
pinterest.follow_board(board_id=b['id'])
# Instead of break you need a way to pause for some time in order to not get banned from pinterest.
break
users = search_users()
for u in users:
pinterest.follow_user(user_id=u['id'])
# Instead of break you need a way to pause for some time in order to not get banned from pinterest.
break