Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

How to use "selftext:not" parameter #78

Open
reagle opened this issue Aug 12, 2020 · 1 comment
Open

How to use "selftext:not" parameter #78

reagle opened this issue Aug 12, 2020 · 1 comment

Comments

@reagle
Copy link

reagle commented Aug 12, 2020

Without the API, I'm able to search via selftext:not:

pushshift_query = f"https://api.pushshift.io/reddit/submission/search/?subreddit={subreddit}&after={after}&before={before}&selftext={query}&selftext:not={exclude}"

What is the equivalent here? selftext_not and selftextnot don't seem to work.

@ethanplee14
Copy link

Turns out the function psaw_api.search_submissions() simply takes a kwargs and builds a get url with the key value pairs to hit the pushshift endpoint. With that being the case all you'd need to do is pass in selftext:not into the kwargs as a key and the query as it's value. Of course, python doesn't allow a colon and the not keyword when assigning a key, so instead you can just pass in a dictionary with the spread operator as the kwargs.

So instead of this:
psaw_api.search_submissions(subreddit="politics", selftext="[removed]|[deleted]")

you can do this:
psaw_api.search_submissions(**{"subreddit": "politics", "selftext:not": "[removed]|[deleted]"})

With this example I'm able to search for text that is not removed or deleted. An extra interesting behavior that might be useful to note is that if you pass in a praw instance into your psaw api, psaw will request the submission ids from pushshift, but then lookup those submissions live using praw, therefore there can be differences between the current submission and what was archived by pushshift.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants