Skip to content

Commit

Permalink
Merge pull request #24 from bstoilov/fix-bug-in-search
Browse files Browse the repository at this point in the history
fix bug in search, query was not escaped properly
  • Loading branch information
bstoilov committed Nov 19, 2019
2 parents 433c896 + da55af9 commit 072819e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion messages_example.py
Expand Up @@ -83,4 +83,4 @@ def send_message(username, message):
# pinterest.send_message(conversation_id=conversation_id, pin_id="(pin_id)", message="hey")


send_message(username='hknives', message='hi2')
send_message(username='username', message='Hi')
6 changes: 4 additions & 2 deletions py3pin/Pinterest.py
Expand Up @@ -368,16 +368,17 @@ def delete_invite(self, board_id, invited_user_id, also_block=False):
def search(self, scope, query, page_size=250):

next_bookmark = self.bookmark_manager.get_bookmark(primary='search', secondary=query)

if next_bookmark == '-end-':
return []

terms = query.split(' ')
query = "%20".join(terms)
escaped_query = "%20".join(terms)
term_meta_arr = []
for t in terms:
term_meta_arr.append('term_meta[]=' + t)
term_arg = "%7Ctyped&".join(term_meta_arr)
source_url = '/search/{}/?q={}&rs=typed&{}%7Ctyped'.format(scope, query, term_arg)
source_url = '/search/{}/?q={}&rs=typed&{}%7Ctyped'.format(scope, escaped_query, term_arg)
options = {
"isPrefetch": False,
"auto_correction_disabled": False,
Expand All @@ -392,6 +393,7 @@ def search(self, scope, query, page_size=250):
resp = self.get(url=url).json()

bookmark = resp['resource']['options']['bookmarks'][0]

self.bookmark_manager.add_bookmark(primary='search', secondary=query, bookmark=bookmark)
return resp['resource_response']['data']['results']

Expand Down

0 comments on commit 072819e

Please sign in to comment.