This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
A year and a half ago. Today, I'm back with a much-improved stable version.
What is PMTW
PMTW is the Python Moderator Toolbox Wrapper. It's a Python module for interacting with Moderator Toolbox usernotes and settings from within Python, featuring read/write functionality for both. This module is potentially useful if you want to backup your usernotes, log them through a bot, or perform bot actions based on a usernote (somebody left a ban usernote, but forgot to issue the ban? Build a bot to notify modmail!). Read more about what you can do with PMTW in the documentation.
Q & A
Q: What do I need to use PMTW?
PMTW requires python 3.7 , praw 7 , and a subreddit you're a moderator with wiki permissions on.
Q: I'm already using pmtw version 0.2.1. Is it safe to upgrade?
A: Absolutely! While the 1.x version of PMTW is essentially a ground-up rewrite, backwards compatibility was an important consideration for this project. Version 1.1.1 has compatibility wrappers for the 0.2.1 syntax, making it a drop in replacement, even going so far as to include the quirk of printing the shortlink when adding a usernote, and private methods from 0.2.1 (for Usernotes only). The one and only place there's a discrepancy is in the text of deleting notes - 0.2.1 reported the note timestamp in milliseconds. PMTW will always report this timestamp in seconds, even when using compatibility wrappers.
Q: Wrappers? Plural?
A: Yes, plural. PMTW also has a wrapper for PUNI, for anybody that might have scripts lying around using that module they'd like to be able to use with modern versions of PRAW, since PUNI is limited to PRAW version 7.1.0 or lower. The compatibility wrapper for PUNI isn't quite drop in, but only requires replacing import puni
with from pmtw import puni_UserNotes, puni_Note
and replacing the periods in any references to puni.UserNotes
and puni.Note
with underscores. The only way in which PMTW's PUNI compatibility shouldn't be a perfect recreation should be that you're able to use the full usernote space, instead of half the available space that PUNI was limited to.
Q: I've use PMTW in the past. What new functionality does 1.1.1 offer me?
A: Beyond the different class and function names, PMTW 1.1.1 does offer some new functionality:
- Usernotes has a list_all_notes function build in, which will return a list of all usernotes on your wiki page, sorted by time.
- ToolboxNote, the replacement class for Note, stores Toolbox-compressed links in the
Note.link
variable, and the expanded url in theNote.url
variable, allowing access to both - A Note can be added upon creation by passing a ToolboxUsernotes object as part of instantiation, instead of creating the note and adding it needing to be two separate operations (though you can still do it in two!)
- The new Toolbox class has convenience methods for pruning notes, searching notes, and exporting notes to a CSV file.
- Any Toolbox setting can be modified and saved.
- ToolboxUsernotes and ToolboxSettings have a custom-built streaming method which streams the wikipage revisions, allowing you to use a stream for updates without pulling the entire pages every time the stream checks for new content.
Q: Looking at the Settings wiki page after editing it through PMTW gives me slightly different output than if I save through Toolbox. What gives?
A: PMTW always encodes any strings that might be encoded in Toolbox for safety reasons. As these fields might be encoded anyways, Toolbox will correctly decode them, and the difference in formatting reflected in the wiki page is transparent in usage.
Q: Any known bugs I should be aware of?
A: One, which concerns the settings page. On a subreddit with no Toolbox Settings page, or a minimal configuration, several parts of the JSON which, if Toolbox is fully configured, exist as lists or arrays only exist as empty strings; this will cause a Toolbox object to fail to properly initialize. This is a problem I hope to resolve in the next few days. If you find anything else, do let me know!
Q: Are you part of the Moderator Toolbox team?
A: Nope, this is totally independent from the excellent work they do. They're kind enough to post their specifications, allowing these sorts of third-party tools without the need for reverse-engineering. My only contribution is a single line change in version 5.6.5.
Q: Okay, I'm sold. How do I get PMTW?
PMTW is available on PyPI and installable through pip: pip install pmtw
(or pip3 install pmtw
). The code is on Github, and you can read the documentation on ReadTheDocs
In Closing
I hope that PMTW is a useful tool for some of you. Feature requests, bug reports, and pull requests are always more than welcome.
Subreddit
Post Details
- Posted
- 2 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/redditdev/c...