Skip to main content

Monitor a directory for new files

Project description

SpongeBot

Monitor a directory for new files

When instantiating a new SpongeBot, you need to provide it with a path to a directory and a callback function. The callback function is called each time a new file is added to the directory, passsing the name of the new file as the first parameter. SpongeBot will run as a thread, making it possible to run multiple SpongeBots simultaneously.

A typical usecase for SpongeBot would look like this:

from spongebot import SpongeBot

def my_callback_function(file_name):
	print('A new file was added to the directory!')

 sb = SpongeBot('./my_directory', my_callback_function)
 sb.start()

The following parameters can be passed to SpongeBot:

  • path: The path to the directory that needs to be monitored
  • callback: A callable that takes a filepath as the first parameter
  • interval: The interval length in seconds that determines how frequently SpongeBot checks for new files. Defaults to 2 seconds.
  • static_args: A list that will be unpacked and passed to the callback function
  • static_kwargs: A dictionary that will be unpacked and passed to the callback function
  • snapshot_file: A file that can be used by SpongeBot to keep track of the files tht are already in the directory. This is used to make SpongeBot more robust in the case of system crashes. Defaults to "./.spongeBot_snapshot.txt".

Another example that uses more features of SpongeBot:

from spongebot import SpongeBot
import pandas as pd


def my_callback_function(file_name, data_pool, verbose=False):
	if verbose:
		print('Processing file ' + file_name)
	df = pd.from_csv(file_name)
	with open(data_pool, 'a') as f:
		df.to_csv(f, index=False, header=False)

data_pool = pd.from_csv('')

sb = SpongeBot(
	'./file_pool/',
	my_callback_function,
	interval=30.0,
	static_args=['./big_data_pool.csv'],
	static_kwargs={'verbose': True},
	snapshot_file='./snapshot_spongeBot.txt')
sb.start()
print('SpongeBot is now running!')

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

spongebot-0.1.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spongebot-0.1.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file spongebot-0.1.0.tar.gz.

File metadata

  • Download URL: spongebot-0.1.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

File hashes

Hashes for spongebot-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a04d1a5d7e5c901393fa817d1683bfeb43fb401866bc5f33925dbda4fbeb013c
MD5 43a444a716f1dbcc0f424357628c5980
BLAKE2b-256 976ad73d5a5e02b872b9099b06b9f7f4a2e63227aafe387590f994a56c9e9c70

See more details on using hashes here.

File details

Details for the file spongebot-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: spongebot-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

File hashes

Hashes for spongebot-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 44970f2817dae84472deadb75538ae919f42cc1ac4993e6a8c0d8ec2bddbf3fa
MD5 56c4b43db91b52c443d919464680dc2b
BLAKE2b-256 675638bd9c7c9f90bdbb5124777b231d5ea7308e4270e0d5b330aa653e274e15

See more details on using hashes here.

Supported by

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