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
OpenQuake's Engine for Seismic Hazard and Risk Analysis

OpenQuake Engine The OpenQuake Engine is an open source application that allows users to compute seismic hazard and seismic risk of earthquakes on a g

Global Earthquake Model 281 Dec 21, 2022
This is Source Code of PdiskUploaderBot

PdiskUploaderBot This is the source code of PdiskUploaderBot. And the developer of this bot is AJTimePyro, His Telegram Channel & Group. You can use t

Abhijeet 8 Oct 20, 2022
An advanced Twitter scraping & OSINT tool written in Python that doesn't use Twitter's API, allowing you to scrape a user's followers, following, Tweets and more while evading most API limitations.

TWINT - Twitter Intelligence Tool No authentication. No API. No limits. Twint is an advanced Twitter scraping tool written in Python that allows for s

TWINT Project 14.2k Jan 03, 2023
A bot which is a ghost and you can make friends with it

This is a bot which is a ghost and you can make friends with it. It will haunt your friends. Explore and test the bot in replit !

Siwan SR 0 Oct 06, 2022
A bot that is an updated & modified version of calvinnfernando's WebReg-Bot

WaitList-Bot A bot that is an updated & modified version of calvinnfernando's WebReg-Bot to automate getting into waitlisted classes in UCSD WebReg on

Issac In 1 Dec 01, 2022
Discord-Mass-Mention - Yup the title says it all

Protocol - Mass Mention (i havent tested this with any token other than my own t

Mallowies 14 Nov 06, 2022
Injector/automatic translator (using deepL API) for Tsukihime Remake

deepLuna Extractor/Editor/Translator/Injector for Tsukihime Remake About deepLuna, from "deepL", the machine translation service, and "Luna", the name

30 Dec 15, 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
🎀 First and most powerfull open source clicktune botter

CTB 🖤 Follow me here: Discord | YouTube | Twitter | Github 🐺 Features: /* *- The first *- Fast *- Proxy support: http/s, socks4/5, premieum (w

Iтѕ_Ѵιcнч#1337 22 Aug 29, 2022
Sukoshi is a proof-of-concept Python implant that leverages the MQTT protocol for C2 and uses AWS IoT Core as infrastructure.

Sukoshi | 少し Overview Sukoshi is a proof-of-concept Python implant that leverages the MQTT protocol for C2 and uses AWS IoT Core as infrastructure. It

Steven Patterson 37 Oct 29, 2022
A Really Simple and Advanced Google Colab NoteBook to Setup and start using Rclone on Google Colab easily.

Rclone on Google Colab (Advanced!) 🔥 1.Setup and Start using Rclone on Google Colab and Create/Edit/View and delete your Rclone config file and keep

Dr.Caduceus 14 May 24, 2022
Trading Strategies (~50%) developed by GreenT on QuantConnect platform over the autumn quarter

Trading Strategies ~50% of codes from the Applied Financial Technology Course. Contributors: Claire W. Derrick T. Frank L. Utkarsh T. Course Leads: Dy

Utkarsh 2 Feb 07, 2022
"zpool iostats" for humans; find the slow parts of your ZFS pool

Getting the gist of zfs statistics vpool-demo.mp4 The ZFS command "zpool iostat" provides a histogram listing of how often it takes to do things in pa

Chad 57 Oct 24, 2022
New developed moderation discord bot by archisha

Monitor42 New developed moderation discord bot by αrchιshα#5518. Details Prefix: 42! Commands: Moderation Use 42!help to get command list. Invite http

Kamilla Youver 0 Jun 29, 2022
Python wrapper for eBay API

python-ebay - Python Wrapper for eBay API This project intends to create a simple python wrapper around eBay APIs. Development and Download Sites The

Roopesh 99 Nov 16, 2022
A wrapper for aqquiring Choice Coin directly through a Python Terminal. Leverages the TinyMan Python-SDK.

CHOICE_TinyMan_Wrapper A wrapper that allows users to acquire Choice Coin directly through their Terminal using ALGO and various Algorand Standard Ass

Choice Coin 16 Sep 24, 2022
Prisma Cloud utility scripts, and a Python SDK for Prisma Cloud APIs.

pcs-toolbox Prisma Cloud utility scripts, and a Python SDK for Prisma Cloud APIs. Table of Contents Support Setup Configuration Script Usage CSPM Scri

Palo Alto Networks 34 Dec 15, 2022
Predict the Site EUI, given the characteristics of the building and the weather data for the location of the building.

wids_datathon_2022 Description: Contains a data pipeline used to predict energy EUI Goals: Dataset exploration Automating the parameter fitting, gener

1 Mar 25, 2022
Bot inspirado no Baidu Antivírus

Baidu Bot Bot inspirado no lendário Baidu Antivírus Informações O programa foi inteiramente feito em Python, sinta-se livre para fazer qualquer altera

Caio Eduardo de Albuquerque Magalhães 1 Dec 18, 2021
A visualization of people a user follows on Twitter

Twitter-Map This software allows the user to create maps of Twitter accounts. Installation git clone Oliver Greenwood 12 Jul 20, 2022