A bot framework for Reddit to manage threads, wiki pages, widgets, menus and more.

Overview

Sub Manager

PyPI Python version Framework Tests Pytest Pre-Commit Code style wemake Code style Black

License Maintainer PyPI status GitHub version PyPI version PyPI wheel Subreddit subscribers

Tests status Lint status Mega-Linter Semgrep scan CodeQL analysis Checked with MyPy Awesome badges

Sub Manager is a bot framework for Reddit to automate a variety of tasks on one or more subreddits, and can be configured and run without writing any code. Its initial application was to automatically generate, create, pin and update threads, as well as related tasks. Additionally, it can be used to automatically sync and reformat content between wiki pages, widgets and threads, as well as marked sections of the same (including the sub's sidebar and other content). It includes support for automatically installing a Systemd service unit for real-time operation on modern Linux distributions, which is used in production for the r/SpaceX subreddit, and it can also be run by any other means you choose on your system.

Legal Disclaimer: For the avoidance of doubt, Sub Manager and the r/SpaceX Github org and subreddit are unofficial fan creations, and have no affiliation with nor endorsement by Reddit or SpaceX, which are trademarks of their respective companies.

Installation

Note: You may need to substitute python3 for python in the commands below on some Linux distros where python isn't mapped to python3 (yet).

Create and activate fresh virtual environment

While Sub Manager can be installed in your system Python, we highly recommend you create and activate a virtual environment to avoid any conflicts with other packages on your system or causing any other issues. Using the standard tool venv, you can create an environment as follows:

python -m venv your-env-name

You can then activate it with the following on Linux and macOS,

source your-env-name/bin/activate

or on Windows (cmd),

.\your-env-name\Scripts\activate.bat

Of course, you're free to use any environment management tool of your choice (conda, virtualenvwrapper, pyenv, etc); these steps are just an example.

Download and install

To download and install the package from the Python Package Index (PyPI), simply activate your environment and run

python -m pip install submanager

Alternatively, if you want to use the exact pinned dependencies we do, you can clone this repo and install from the requirements.txt file:

git clone https://github.com/r-spacex/submanager.git
cd submanager
python -m pip install -r requirements.txt
python -m pip install .

Usage

To use Sub Manager, you'll need to activate the appropriate environment you created previously, and then execute its main entrypoint. For example, with venv under bash,

source your-env-name/bin/activate
submanager <command>

To see the various commands and options available, pass it the --help flag.

Contributing

For information on how to contribute to Sub Manager, including reporting issues, setting up a development environment and contributing code, see the Contributing Guide.

Configuration

First, you'll want to generate the primary Sub Manager user config file, in order to tell it what you want it to do. To do so, simply run submanager generate-config to generate it at the default path, and a stock config file with some starting examples will be output (formatted as TOML for humans). The static config file, which stores user configuration as human-friendly TOML, is located in the submanager subdirectory OS-appropriate user config directory, and the dynamic config file, which stores persistent internal state (e.g. current threads being managed) as machine-friendly JSON, is located in submanager subdirectory OS-appropriate user state directory. To view the full paths to and status of these files on your system, simply run submanager get-config-info. You can specify an alternate config file for one or both with the respective --config-path and --dynamic-config-path options, allowing you to run multiple instances of the bot simultaneously on the same machine (for example, to avoid cramming everything into one big configuration file, or use multiple cores).

To improve robustness and enforce safe maintenance practices, Sub Manager must now be stopped and restarted to read-in updated config. Individual modules, such as sync_manager and thread_manager, can be enabled and disabled via their corresponding enabled options, and can be further configured as described below. To perform a variety of checks that your configuration is valid and will result in a successful run, without actually executing any state-changing Reddit actions, run submanager validate-config; if an error occurs, informative output will explain the problem and, often, how to fix it.

Configuring credentials

Starting with Sub Manager v0.5.0 and later, the Reddit account to use for a given action can be specified per module (sync_manager, thread_manager), per task (sync item, thread) and even per source and target, as well as globally. You'll need to configure and register the account(s) involved for Reddit app access with the Reddit API. We recommend you configure your credentials in praw.ini and simply refer to them via the PRAW site_name argument in the config subtable of the respective account listed under the accounts table, which will avoid any secrets leaking if you accidentally or deliberately store your config.toml somewhere public. However, if you prefer, the various arguments that praw.Reddit() can accept, e.g. username, password, client id, client secret, refresh token etc) can be also all be included as subkeys under the config subtable of the named account in the accounts table. Sub Manager v0.5.0 supported the new token manager refresh token handling Reddit announced in early 2021, while v0.6.0 dropped that support along with PRAW due to Reddit reverting that change. While this occurred before to the first wide public release of Sub Manager (v0.6.0), this change is nevertheless transparent to users, as Sub Manager handles this for you.

Posting intervals

If posting new threads is enabled for a configured thread item, it can be set to either post daily, monthly, yearly etc. as soon as the period ticks over (e.g. first of the month), or at an interval of every N periods after the previous thread was posted.

new_thread_interval is specified as a string, either in the form "UNIT" (e.g. "daily", "month", etc) to trigger the first behavior, or "N UNIT" (e.g. "10 weeks", "1 year", etc) to invoke the second, where N is a positive integer and UNIT is a supported period unit. Supported period units for both include years, months, days, hours, minutes and seconds; weeks are currently supported for the latter, but not the former (since there is no unambiguously agreed-upon, locale-independent start of a week, and they don't divide evenly into months or years). For either form, the units can be given with or without s or ly as suffices.

There's currently a minor limitation with this as currently implemented: getting it to create a new thread "on-demand" rather than on a schedule (or not at all) is not completely obvious. There is a relatively simple workaround, however—just set the new_thread_interval to false, and then whenever you want a new thread, set it to e.g. 1 day, wait repeat_interval_s seconds for it to create the new thread (or manually restart it, if you're impatient), and then set it back to false.

We will soon add a proper feature for this, likely in the form of a new CLI command, e.g. submanager create-thread <thread_name>, to programmatically tell the running Sub Manager instance to create a new post on-demand.

Syncing sections

The patterns of text specified in source and targets are searched for in pseudo-Markdown "comments", i.e. empty links that don't appear in the rendered text, like so:

[](#/ <PATTERN><PATTERN_START>)

Example section content

[](#/ <PATTERN><PATTERN_END>)

This allows easily syncing just specific sections between sources and targets.

If any variable (e.g. pattern) is not specified for a target, the value is recursively inherited from the respective defaults table in the sync pair, and then sync config section, including the context sub-table in each as well as the default_context in the config. Conversely, any replace_patterns for a specific target are applied after (and in addition) to those specified in source for all targets; note the source section is not actually modified unless it is specified as a target.

Running as a service

To install a Systemd user service that will run Sub Manager automatically, activate your Sub Manager environment and simply run the submanager install-service command. By default, this will install a user-level service named submanager.service which will run Sub Manager with the primary configuration. If you'd like to install another service with a different config, specify the config file path as usual with --config-path, and (if you don't want the service to overwrite the default one, so you can run as many as you want at once), a custom suffix; the resulting service will be named submanager-<suffix>.service.

The installed service can be enabled and started in the typical way,

systemctl --user daemon-reload
systemctl --user enable submanager
systemctl --user start submanager

and you can check its status and log, respectively, with the usual

systemctl --user status submanager
journalctl --user -xe -u submanager

Note that there are a few considerations to keep in mind when running as a user instance of Systemd, most notably to get it to autostart on boot rather than login and persist after the user is logged out (e.g. on a server, VPS or other unattended box).

Comments
  • Complete final pre-release prep

    Complete final pre-release prep

    • [x] Update Readme badges and add PyPI
    • [x] Resolve issues running online workflows from forks
    • [ ] Update release instructions
    • [ ] Run pre-commit autoupdate
    • [ ] Pip compile dependencies into requirements.txt
    opened by CAM-Gerlach 2
  • Release Sub Manager version 0.6.0

    Release Sub Manager version 0.6.0

    • [x] Complete preliminaries
    • [x] Update pinned deps
    • [x] Update pre-commit hooks
    • [x] Build and test on RPi
    • [x] Transition new version to production on RPi
    • [x] Update documentation and finish release PR
    • [x] Rebuild and upload to PyPI on RPi
    • [x] Re-install production release on Pi
    • [x] Finalize release
    • [x] Cleanup on the RPi
    • [x] Cleanup locally
    • [x] Announce on Slack, etc.
    opened by CAM-Gerlach 1
  • Fix unimport linter repo URL.

    Fix unimport linter repo URL.

    Thank you for using Unimport, there was a slight change in the URL, the old URL works because it is redirected to the new one, but I changed it to the new one just in case.

    opened by hakancelikdev 0
  • Execute pre-release cleanup and preparation for CIs and ancillaries

    Execute pre-release cleanup and preparation for CIs and ancillaries

    A number of pre-release tasks:

    • [x] Split CI into lint and test workflows
    • [x] Add security policy
    • [x] Adopt Keep a Changelog format
    • [x] Add README badges
    opened by CAM-Gerlach 0
  • Add semgrep workflow to CI pipeline, for real this time

    Add semgrep workflow to CI pipeline, for real this time

    Semgrep didn't actually run over the whole repo in the previous are, so the outstanding issues went unreported, per returntocorp/semgrep-action#352 . This PR is a redo of #3 to commit both adding semgrep and fixing its issues in one clean, passing-build, atomic commit.

    opened by CAM-Gerlach 0
  • Update CIs following v0.6.0 release and test changes in new Mega-Linter preview release

    Update CIs following v0.6.0 release and test changes in new Mega-Linter preview release

    • [x] Remove link check disables for PyPI links that didn't work yet
    • [x] Re-enable Bandit and Black on Mega-Linter following fixing blocking Mega-Linter issues with those linters
    • [ ] Bump pre-commit and dep versions
    • [ ] Port improvements from spyder-docs
    • [ ] Add support for Python 3.10 to matrix and setup.cfg
    • [ ] Consider re-basing to 0.6.x?
    • [ ] (Fixup to switch back to production Mega-Linter once CIs pass and the new build is live)

    Mega linter blocking issues reference: Bandit nvuillam/mega-linter#679 and Black nvuillam/mega-linter#681 , both in nvuillam/mega-linter#682

    Task 
    opened by CAM-Gerlach 2
Releases(v0.6.0)
  • v0.6.0(Aug 25, 2021)

    Major release of Sub Manager, with a complete rewrite and numerous new features, enhancements and fixes.

    Added

    • Full command-based CLI with many more options, including separate start and run commands
    • Command get-config-info to print information about the config and list endpoints
    • Command install-service to automatically install a systemd service to run the bot
    • Command generate-config to generate a user config file with example defaults
    • Command validate-config to validate the current config file, offline or online
    • Command cycle-threads to post new versions of the indicated threads
    • --debug flag, to control whether user-friendly error messages or full tracebacks are printed
    • Config option approve_new to control if new posted threads are automatically approved (default)
    • "auto" option for pin_mode (default) will unpin the old thread and pin the new if currently pinned
    • truncate_lines option for source and target endpoints, to truncate to a specified number of lines
    • More fillable/replaceable variables in thread titles
    • Comprehensive offline and online functional tests exercising the options of every supported command
    • Exhaustive suite of pre-commit checks to validate correctness, best-practices, conventions and style
    • Tests, linting and analysis all run across a matrix of platforms/versions in CIs via Github Actions

    Changed

    • Reorganize much of user and dynamic config for consistency and future extensibility
    • Use Platformdirs to install config and state files into platform-appropriate locations
    • Validate config and resync all sources for the first run, to handle any config changes
    • Use Pydantic for config, allowing robust access and user-friendly validation
    • Vastly improved error handing of almost all areas, with much more helpful, user friendly messages
    • Safety run multiple instances via locking, to enable new commands and avoid strange bugs
    • Enable thread redirect in OP and sticky by default (configurable)
    • Inject start and end comments into thread targets, to allow easily adding extra content
    • Formally rename everything to Sub Manager, with consistent naming everywhere
    • Refactor from a monolithic script into a modular package, greatly improving organization
    • Make a Python package for installing from Github or from PyPI and add lint and test extras
    • Package is now fully statically typed, improving correctness, robustness and documentation
    • Add/greatly improve docs including Readme, Contributing Guide, security policy and more
    • Auto-generate pinned requirements files for reproducible dev and production installation

    Fixed

    • Issues with hierarchical config defaults not getting inherited correctly
    • Not syncing new targets until a change is made in the source
    • Not injecting appropriate line breaks in targets for some sources, causing formatting issues
    • Many other edge-case bugs and issues

    Removed

    • Config file no longer generated automatically if its not present, use generate-config instead
    • Drop previous support for token managers, in line with Reddit and PRAW changes
    Source code(tar.gz)
    Source code(zip)
Owner
r/SpaceX
A central location for information and collaboration on all of the awesome projects coming out of r/SpaceX
r/SpaceX
Python client for ETAPI of Trilium Note.

Python client for ETAPI of Trilium Note.

33 Dec 31, 2022
A telegram bot to monitor the latest NFT price on BSC.

NFT_Monitor This is a telegram bot for monitoring price and ranking of NFT on Binance Smart Chain. Can fetch latest ranking and price in real time. .P

Niko Pang 10 Oct 09, 2022
A Telegram Userbot to play Audio and Video songs / files in Telegram Voice Chats

TG-MusicPlayer A Telegram Userbot to play Audio and Video songs / files in Telegram Voice Chats. It's made with PyTgCalls and Pyrogram Requirements Py

4 Jul 30, 2022
PRNT.sc Image Grabber

PRNTSender PRNT.sc Image Grabber PRNTSender is a script that takes images posted on PRNT.sc and sends them to a Discord webhook, if you want to know h

neox 2 Dec 10, 2021
Home Assistant Hilo Integration via HACS

BETA This is a beta release. There will be some bugs, issues, etc. Please bear with us and open issues in the repo. Hilo Hilo integration for Home Ass

66 Dec 23, 2022
Lib for create and show QRCode to PIX, you can show this code in another applications for payment by final consumer.

Biblioteca para a geração de codigos QR (BRCode como chamados na documentação do BACEN) a fins de facilitar a exibição para pagamentos ao consumidor.

João Camargo 13 Oct 05, 2022
This script will detect changes in your session using Discords built in Gateway.

Detect Session Gateway This script will detect changes in your session using Discords built in Gateway. What does this log? Discord build version Oper

Omega 5 Dec 18, 2021
Definitive Guide to Creating a SQL Database on Cloud with AWS and Python

Definitive Guide to Creating a SQL Database on Cloud with AWS and Python An easy-to-follow comprehensive guide on integrating Amazon RDS, MySQL Workbe

Kenneth Leung 6 Aug 17, 2022
🔍 Google Search unofficial API for Python with no external dependencies

Python Google Search API Unofficial Google Search API for Python. It uses web scraping in the background and is compatible with both Python 2 and 3. W

Avi Aryan 204 Dec 28, 2022
A Python interface between Earth Engine and xarray for processing weather and climate data

wxee What is wxee? wxee was built to make processing gridded, mesoscale time series weather and climate data quick and easy by integrating the data ca

Aaron Zuspan 160 Dec 31, 2022
aws-lambda-scheduler lets you call any existing AWS Lambda Function you have in a future time.

aws-lambda-scheduler aws-lambda-scheduler lets you call any existing AWS Lambda Function you have in the future. This functionality is achieved by dyn

Oğuzhan Yılmaz 57 Dec 17, 2022
Telegram bot to stream videos in telegram Voice Chat for both groups and channels

Telegram bot to stream videos in telegram Voice Chat for both groups and channels. Supports live steams, YouTube videos and telegram media. Supports scheduling streams, recording and many more.

Akki ThePro 2 Sep 11, 2022
Auxiliator is telegram bot for basic web-application analysis

Auxiliator Auxiliator is telegram bot for basic web-application analysis What for? Sometimes there is no access to your main PC, where you can scan we

Revoltage 13 Dec 26, 2021
A python package to fetch results of various national examinations done in Tanzania.

Necta-API Get a formated data of examination results scrapped from necta results website. Note this is not an official NECTA API and is still in devel

vincent laizer 16 Dec 23, 2022
MONAI Deploy App SDK offers a framework and associated tools to design, develop and verify AI-driven applications in the healthcare imaging domain.

MONAI Deploy App SDK offers a framework and associated tools to design, develop and verify AI-driven applications in the healthcare imaging domain.

Project MONAI 49 Dec 23, 2022
Discord Token Generator based on HTTPX, makes unverified tokens and automatically joins your server! this is used for memberboosting

Discord Token Generator | 2021 Features: (1) hCaptcha Bypasser, latest hfuck.py Updated by me (2) Free Proxy Support/Scrapper (3) Custom Realistic Dat

2 Nov 30, 2021
A Telegram bot that scrapes websites for available vaccination appointments to notify users. (German)

@dachau_impf_bot 🇬🇧 A Telegram bot to check the contents of https://termin.dachau-med.de for available slots and inform users of the available dates

1 Nov 21, 2021
Stream Telegram files to web

Telegram File Stream Bot A Telegram bot to stream files to web Demo Bot » Report a Bug | Request Feature Table of Contents About this Bot Original Rep

Wrench 572 Jan 09, 2023
This is a telegram bot hosted by a Raspberry Pi equipped with a temperature and humidity sensor. The bot is capable of sending plots and readings.

raspy-temperature-bot This is a telegram bot hosted by a Raspberry Pi equipped with a temperature and humidity sensor. The bot is capable of sending p

31 May 22, 2022
Solves bombcrypto newest captcha

Solves Bombcrypto newest captcha A very compact implementation using just cv2 and ctypes, ready to be deployed to your own project. How does it work I

19 May 06, 2022