PRAWvents, Events for PRAW
A simple wrapper to write event-based bots with PRAW.
Scope
You can register event handlers for everything thats based on the praw stream_generator Any other functionality is offered as-is, since this subclasses the main PRAW Reddit instance.
A async version of this should be possible, but is not yet planned.
Quickstart
This is a simple bot that will print out the subreddit and the submission title for all posts in the subreddits AskReddit and pics, while skipping the existing posts in AskReddit. This example assumes the presence of a praw.ini in your working directory.
from prawvents import EventReddit
from praw import reddit
r = EventReddit(user_agent=f"ExampleBot for prawvents version (0.0.1) by /u/laundmo") # change the description and username!
sub1 = r.subreddit("AskReddit")
sub2 = r.subreddit("pics")
def handle_exception(e): # very dumb exception handler
print(e)
@r.register_event(sub1.stream.submissions, err_handler=handle_exception, skip_existing=True)
@r.register_event(sub2.stream.submissions, err_handler=handle_exception)
def handle(submission: reddit.Submission):
print(submission.subreddit, submission.title)
r.run_loop()
Docs
RedditEventDecorator Objects
class RedditEventDecorator()
Decorator class for event handlers.
__init__
| __init__(reddit: praw.Reddit, stream: RStream, err_handler: Callable)
Initialise RedditEventDecorator.
Arguments:
redditEventReddit - TheEventRedditinstancestreamRStream - The stream to which the event responds.err_handlerCallable - A function thats called with the exception as a argument.
__call__
| __call__(f: Callable) -> Callable
Set the event handler.
Arguments:
fCallable - The event handler function.
Returns:
Callable- The function.
EventReddit Objects
class EventReddit(praw.Reddit)
Main Reddit instance, subclass of praw.Reddit.
Arguments:
prawpraw.Reddit - Praw Reddit superclass.
__init__
| __init__(*args, **kwargs)
Initialise EventReddit. All arguments are passed through to praw.Reddit
register_event
| register_event(stream: RStream, err_handler: Callable = None, **kwargs) -> RedditEventDecorator
Register a event, should generally be used as a decorator like this:
@r.register_event(subreddit.stream.submissions, err_handler=handle_exception)
def event_handler(submission):
pass
Arguments:
streamRStream - The stream to which the event responds.err_handlerCallable, optional - The error handler for this event. Defaults to None.
Returns:
RedditEventDecorator- The decorator instance.
handle_exception
| handle_exception(f: Callable, e: Exception)
Handle a Exception happening in a function f
Arguments:
fCallable - The function which threw the exception.eException - The exception which was thrown.
Raises:
e- The Exception that was thrown.
run_stream_till_none
| run_stream_till_none(stream: RStream, funcs: Iterable[Callable]) -> None
Runs a stream until none is returned
Arguments:
streamRStream - The finalized stream to run.funcsIterable[Callable] - The functions which handle this stream.
run_loop
| run_loop(interweave=True) -> None
Run the event loop. If interweave is Truthy, events from multiple streams will be mixed to ensure a single high-traffic stream cant take up the entire event loop. This is highly recommended.
Arguments:
interweavebool, optional - Whether to interweave streams to ensure fair distribution. Defaults to True.
Metadata
Release files for prawvents 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| prawvents-0.1.tar.gz | 4.5 kB | Without provenance | Details for prawvents-0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| prawvents-0.1-py3-none-any.whl | Python 3 | none | any | Details for prawvents-0.1-py3-none-any.whl |
Total release size: 10.2 kB
Release files / prawvents-0.1.tar.gz
| Download URL | prawvents-0.1.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
95bd3fe810d78fe5181074ef52234f4ff0be646a11773260218aaa3b8bca1eaf
|
|
BLAKE2b-256 checksum How to use checksums |
c051c3814d76b52654bc142b8e199d9c7e8e5dc5bd073fe1a2d666ede96873e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0.post20201221 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.0
|
Release files / prawvents-0.1-py3-none-any.whl
| Download URL | prawvents-0.1-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
15eb677095db1d6f765eb1c06b4d9e8fdd09a7793a105df5a9f0972b274f092a
|
|
BLAKE2b-256 checksum How to use checksums |
1421d1dd051665a731c5e7deb4527b26d95f007a7d6964fdb5d6da6f2d355cb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0.post20201221 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.0
|
Security for prawvents 0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.