Skip to content

Commit

Permalink
adding follow examples
Browse files Browse the repository at this point in the history
  • Loading branch information
bstoilov committed Oct 4, 2019
1 parent de98981 commit 8abbf90
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
5 changes: 2 additions & 3 deletions examples.py
Expand Up @@ -143,10 +143,9 @@ def search():
results = []
max_results = 100
search_batch = pinterest.search(scope='boards', query='food')
while len(search_batch) > 0:
while len(search_batch) > 0 and len(results) < max_results:
results += search_batch
if len(results) > max_results:
break
search_batch = pinterest.search(scope='boards', query='food')

return results

Expand Down
63 changes: 63 additions & 0 deletions follow_examples.py
@@ -0,0 +1,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'], board_url=b['url'])
# 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'], username=u['username'])
# Instead of break you need a way to pause for some time in order to not get banned from pinterest.
break

0 comments on commit 8abbf90

Please sign in to comment.