コード例 #1
0
ファイル: shredder.py プロジェクト: PoopsMcButt/Shreddit
 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")
コード例 #2
0
 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")
コード例 #3
0
ファイル: shredder.py プロジェクト: hutchisr/Shreddit
    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)
コード例 #4
0
ファイル: shredder.py プロジェクト: PleasantMachine9/Shreddit
    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")
コード例 #5
0
ファイル: shredder.py プロジェクト: PoopsMcButt/Shreddit
    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))
コード例 #6
0
ファイル: shredder.py プロジェクト: PleasantMachine9/Shreddit
 def _prompt_passwd(self):
     passwd = getpass.getpass("Enter password for Reddit user: "******"Confirm: "):
         raise ShredditError("Passwords do not match")
     return passwd