Skip to main content

A simple telegram bot that monitors changes in directories

Project description

telefilebot

CI codecov Documentation Status PyPI PyPI - Downloads

alt text

Sometimes you have code that runs a long time and you do not want to continuously check if it has finished. If that code writes a file to the disk at the end, maybe you just want a text message when that file is created or modified?

telefilebot allows you to do this with as a simple background listener. All you need is an input YAML file and you can monitor multiple directories for various new files being created.

Installation

pip install telefilebot

Usage

Say you have two directories you want to monitor. In one of them you want to look for text files (files ending with a .txt extension) and the other you only want to scan the top two level directories.

First you need to create a telegram bot and attach it to some group where it can message you.

Now, create a YAML file that looks like this:

name: "file_monitor"
chat_id: "-XXXXXXXX"
token: "XXXXXXX"
logging:
  level: "INFO"
directories:
  "~/my_dir1":
    extensions:
      - .txt
  "~/my_dir2":
  recursion_limit: 0
wait_time: 1

What do these things mean?

  • The name just names the bot.
  • The chat_id and token are from the group and bot you created.
  • logging sets the verbosity of the printout in the terminal.
  • For each directory you want to monitor, create an entry with the directory path. If you want to monitor only certain file extensions, list them under the director. If you only want to recurse down to a certain level in the file structure, enter a recursion limit (here zero means only the path entered and no sub-folders will be scanned).
  • Finally, the wait_time argument specifies in minutes how long to wait between checks of the file system.

Now simply fire up a tmux session (or however you want to the bot to run in the background) and enter

telefilebot --file input.yml

and you are done! Your bot will let you know when new files are added or modified.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

telefilebot-0.2.0.tar.gz (29.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page