Skip to content
Python tool to periodically export usage statistics of a subreddit list in a database.
Python
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
scripts
subreddit_tracker
systemd-service
.gitignore
LICENSE
MANIFEST.in
Pipfile
Pipfile.lock
README.md
praw.ini_sample
setup.py

README.md

subreddit_tracker

Codacy Badge

Extract subscribers and live users count of a list of subreddit defined in a csv file or a sqlite database.

Requirements

  • praw
  • working praw config in ~/.config/ (see praw.ini_sample for an example)

Installation

Installation in a virtualenv with pipenv (recommended) :

pipenv install '-e .'

Installation in the system-wide environment :

python setup.py install

Installation in the systemd-wide environment with pip :

pip install .

Usage

Given a simple txt file subreddit_list.txt

funny
gifs
videos

You can then call (depending on the backend you want) :

subreddit_tracker -f subreddit_list.txt -b csv
subreddit_tracker -f subreddit_list.txt -b sqlite

Autostarting

Systemd services and their respective timers are provided in the systemd-service/ folder.

You will have to change the service files to launch the script in another directory or to launch it with other options (by default the service files launch the script in a pipenv virtualenv located in the same directory as the script).

The timer is set to launch the script every 10 minutes.

After copying the service and timer files in ~/.config/systemd/user/, you can launch the timer with :

systemctl --user daemon-reload
systemctl --user enable --now subreddit_tracker.timer
systemctl --user enable --now subreddit_tracker_sqlite.timer

Help

subreddit_tracker -h
usage: subreddit_tracker [-h] [--debug] [-f FILE] [-n NB_THREADS] [-b BACKEND]

Extract subscribers and live users count of a list of subreddit defined in a
text file.

optional arguments:
  -h, --help            show this help message and exit
  --debug               Display debugging information
  -f FILE, --file FILE  File containing the subreddits (Default : sample file
                        containing popular subreddits)
  -n NB_THREADS, --nb_threads NB_THREADS
                        Number of threads to use. Be sure to have
                        corresponding entries in your praw.ini file
                        (reddit_bot_1... reddit_bot_N).
  -b BACKEND, --backend BACKEND
                        Backend to store the extracted data (sqlite or csv,
                        Default : csv).

Threads

You can use several threads with the -n/--nb_threads argument. Be sure to have corresponding entries in your praw.ini file with different accounts under [reddit_bot_2], [reddit_bot_3], ... headings.

The subreddit list will be divided into N sublists. Each of those will be extracted with a separate reddit account to make things faster.

You can’t perform that action at this time.