def _connect(self): try: self._r = praw.Reddit(self._user, check_for_updates=False, user_agent="python:test:v6.0.5") self._logger.info("Logged in as {user}.".format(user=self._r.user.me())) except ResponseException: raise ShredditError("Bad OAuth credentials") except OAuthException: raise ShredditError("Bad username or password")
def _connect(self): try: self._r = praw.Reddit(self._user, user_agent="python:shreddit:v6.0.4") if self._r.user.me() is None: raise OAuthException(None, None, None) self._logger.info( "Logged in as {user}.".format(user=self._r.user.me())) except ResponseException: raise ShredditError("Bad OAuth credentials") except OAuthException: raise ShredditError("Bad username or password")
def _build_iterator(self): user = self._r.user.me() listings = [] iterators = [] if self._item == "comments": listings.append(user.comments) elif self._item == "submitted": listings.append(user.submissions) elif self._item == "overview": listings.extend([user.comments, user.submissions]) for listing in listings: for sort in self._sort: if sort == "new": iterators.append(listing.new(limit=None)) elif sort == "top": iterators.append(listing.top(limit=None)) elif sort == "hot": iterators.append(listing.hot(limit=None)) elif sort == "controversial": iterators.append(listing.controversial(limit=None)) else: raise ShredditError( f'Sorting "{self._sort}" not recognized.') return chain.from_iterable(iterators)
def _connect(self): try: kwargs = { 'check_for_updates': False, 'user_agent': "python:shreddit:v6.0.4" } if self._password: kwargs['password'] = self._password self._r = praw.Reddit(self._user, **kwargs) user = self._r.user.me() if not user: raise ShredditError("Bad user (%r)? Make sure the praw.ini " "file contents are correct." % user) self._logger.info("Logged in as {user}.".format(user=user)) except ShredditError: raise except ResponseException: raise ShredditError("Bad OAuth credentials") except OAuthException: raise ShredditError("Bad username or password")
def _build_iterator(self): item = self._r.user.me() if self._item == "comments": item = item.comments elif self._item == "submitted": item = item.submissions if self._sort == "new": return item.new(limit=None) elif self._sort == "top": return item.top(limit=None) elif self._sort == "hot": return item.hot(limit=None) elif self._sort == "controversial": return item.controversial(limit=None) else: raise ShredditError("Sorting \"{}\" not recognized.".format(self._sort))
def _prompt_passwd(self): passwd = getpass.getpass("Enter password for Reddit user: "******"Confirm: "): raise ShredditError("Passwords do not match") return passwd