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 details)

Uploaded Source

File details

Details for the file telefilebot-0.2.0.tar.gz.

File metadata

  • Download URL: telefilebot-0.2.0.tar.gz
  • Upload date:
  • Size: 29.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for telefilebot-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d3d04116e2f34b5e915780488af166716b8d8c258452234b330aa353412f508b
MD5 70a4d610c69136e533251f6f8e549834
BLAKE2b-256 4f60d69d3a7410ece437e4ac02ffccc2bd84476cc88e418ab55cc851a5ce9427

See more details on using hashes here.

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