Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
LilSpazJoekp
@LilSpazJoekp
the stream_generator method wants to pass params to the function and subreddit.modmail.conversations doesn't accept params
are you okay with this as a work around?
    def modmail_conversations(
        self, other_subreddits=None, sort=None, state=None, **stream_options
    ):
        """Yield unread moderator messages as the become available.

        :param other_subreddits: A list of :class:`.Subreddit` instances for
            which to fetch conversations (default: None).
        :param sort: Can be one of: mod, recent, unread, user
            (default: recent).
        :param state: Can be one of: all, archived, highlighted, inprogress,
            mod, new, notifications, (default: all). "all" does not include
            internal or archived conversations.

        Keyword arguments are passed to :func:`.stream_generator`.

        To print new mail in the unread modmail queue try:

        .. code:: python

           for message in reddit.subreddit('all').mod.stream.\
modmail_conversations():
               print("From: {}, To: {}".format(message.author, message.dest))

        """
        def __modmail_stream_generator(function, pause_after=None, skip_existing=False, attribute_name="id", **function_kwargs):
            """
            This is used instead of the stream_generator in util because :class:`.Modmail.conversations` does not take `params` as an argument
            """
            from ..util import ExponentialCounter, BoundedSet
            exponential_counter = ExponentialCounter(max_counter=16)
            seen_attributes = BoundedSet(301)
            responses_without_new = 0
            valid_pause_after = pause_after is not None
            while True:
                found = False
                for item in reversed(list(function(limit=100, **function_kwargs))):
                    attribute = getattr(item, attribute_name)
                    if attribute in seen_attributes:
                        continue
                    found = True
                    seen_attributes.add(attribute)
                    if not skip_existing:
                        yield item
                skip_existing = False
                if valid_pause_after and pause_after < 0:
                    yield None
                elif found:
                    exponential_counter.reset()
                    responses_without_new = 0
                else:
                    responses_without_new += 1
                    if valid_pause_after and responses_without_new > pause_after:
                        exponential_counter.reset()
                        responses_without_new = 0
                        yield None
                    else:
                        time.sleep(exponential_counter.counter())

        if self.subreddit.display_name == 'mod':
            self.subreddit = self.subreddit._reddit.subreddit('all')
        return __modmail_stream_generator(
            self.subreddit.modmail.conversations,
            other_subreddits=other_subreddits,
            sort=sort,
            state=state,
            **stream_options
        )
Bryce Boe
@bboe
I wonder if there's a way to keep the code a little more DRY.
LilSpazJoekp
@LilSpazJoekp
if this praw-dev/praw@7f2adcf was merged in it would work
and __modmail_stream_generator is just the stream_generator from that pr
Bryce Boe
@bboe
What if we added a exclude_before to stream_generator?
Or something similar?
LilSpazJoekp
@LilSpazJoekp
that could work
Bryce Boe
@bboe
Perhaps you could try that in your PR.
LilSpazJoekp
@LilSpazJoekp
I was thinking about that but didn't know what you would prefer
Bryce Boe
@bboe
I think that'd be a little cleaner of a solution.
LilSpazJoekp
@LilSpazJoekp
okay I can do that
Bryce Boe
@bboe
Awesome.
LilSpazJoekp
@LilSpazJoekp
Sounds good! Sorry for taking so long on this pr. I've been busy with reddit and other bot stuff for a while now.
Bryce Boe
@bboe
No worries. Thanks for the contributions.
LilSpazJoekp
@LilSpazJoekp
Glad I can contribute
I should have it done if not today, with in the next few days
Bryce Boe
@bboe
On the flip side, it's hard to make a lot of progress without swift feedback.
LilSpazJoekp
@LilSpazJoekp
Feedback?
Bryce Boe
@bboe
I don't know if we've been prompt about providing feedback.
LilSpazJoekp
@LilSpazJoekp
Ah yeah
Not sure what can be done to help there
Bryce Boe
@bboe
The more people interested in the project the more help people could get.
LilSpazJoekp
@LilSpazJoekp
Yeah. I don't mind providing feedback where I can.
Bryce Boe
@bboe
Awesome.
LilSpazJoekp
@LilSpazJoekp
While I'm thinking about it what's your thoughts on a async compatible praw
praw that uses aiohttp instead of requests for use in an async environment
for example discord requires the use of async/await for interacting with their api and using praw in a discord bot has some problems working properly
Bryce Boe
@bboe
I would love PRAW to support that, however, I think that effort might be better supported from scratch, or with existing attempts to get it to work, like apraw.
LilSpazJoekp
@LilSpazJoekp
yes
I think it'd be a lot of bloat to support synchronous and asynchronous calls in PRAW.
LilSpazJoekp
@LilSpazJoekp
Bryce Boe
@bboe
Cool.
LilSpazJoekp
@LilSpazJoekp
I just replaced requests with aiohttp and made the methods that make requests asynchronous
haven't done anything with documentation or tests
Bryce Boe
@bboe
Nice, and does it work for your purposes?
LilSpazJoekp
@LilSpazJoekp
for the most part, yes
Bryce Boe
@bboe
It'd be interesting if prawcore could be semi-transparently swapped with asyncprawcore.
LilSpazJoekp
@LilSpazJoekp
hm
I think you're right that having a separate praw and prawcore for async would be better
Bryce Boe
@bboe
Yeah.
LilSpazJoekp
@LilSpazJoekp
maybe it could be a different branch and if you need async praw you could do pip install prawcore[async] and pip install praw[async]
like Rapptz does here https://github.com/Rapptz/discord.py#installing for the voice part of discord.py
Bryce Boe
@bboe
Probably still better as a separate package.
In that case it's an add-on support, which is a bit different than an entire core change.
Alright, gotta head out for now. Great chat.
Thanks for the efforts.
LilSpazJoekp
@LilSpazJoekp
No problem talk to you later!