Created a module to monitor file and URL updates

mdfmonitor-Monitor file and URL updates

https://github.com/alice1017/mdfmonitor

** mdfmonitor ** is a Python module that uses file timestamps and URL Data headers to monitor file and URL updates.

mdfmonitor contains:

FileModificationMonitor

FileModificationMonitor (hereafter referred to as "monitor") monitors ** files ** for updates.

Monitor has a repository with ** timestamp data ** of the file and ** data of the contents of the file **. First of all, insert the original time stamp data and the data of the contents of the file. Next, get the new time stamp data and the contents data of the file, ** compare ** these old data and new data, and if they are different, consider it as ** update ** and make it an object yield. To do.

How to use

It's simple to use.

  1. ʻimport` the module
  2. Create an instance of FileModificationMonitor
  3. Register the file
  4. The monitor method starts monitoring and returns an object, so use the for statement to draw the process.
#!/usr/bin/python

import os
from mdfmonitor import FileModificationMonitor

files = os.listdir(".") # >>> ['sample.txt', 'sample.py']

# create Watcher instnce
monitor = FileModificationMonitor()

# append file to mdfmonitor instance
monitor.add_file("sample.txt")

# or 
# append files to mdfmonitor instance
monitor.add_files(os.listdir("."))

for mdf in monitor.monitor():
    
    print mdf.file.center(30, "=")
    print "Catch the Modification!!"
    print "Old timestamp: %s" % mdf.old_mtime
    print "New timestamp: %s" % mdf.new_mtime
    print "manager: %s" % str(mdf.manager.o_repository)
    print "Diff".center(30,"=")
    print mdf.diff

URLModificationMonitor

URLModificationMonitor (also called "monitor") can monitor URL content updates.

The structure of Monitor is almost the same as FileModificationMonitor. The difference is that it uses the ** Date ** header that comes with the Response header of the URL to find updates, not the timestamp data.

How to use

This is about the same.

  1. ʻimport` the module
  2. Create an instance of ʻURLModificationMonitor`
  3. Register the URL
  4. The monitor method starts monitoring and returns an object, so use the for statement to draw the process.
#!/usr/bin/python

import os
from mdfmonitor import URLModificationMonitor

files = os.listdir(".") # >>> ['sample.txt', 'sample.py']

# create Watcher instnce
monitor = URLModificationMonitor()

# append file to mdfmonitor instance
monitor.add_url("http://sampe.com/path/")

for mdf in monitor.monitor():
    
    print mdf.url.center(30, "=")
    print "Catch the Modification!!"
    print "Old timestamp: %s" % mdf.old_dtime
    print "New timestamp: %s" % mdf.new_dtime
    print "manager: %s" % str(mdf.manager.o_repository)
    print "Diff".center(30,"=")
    print mdf.diff

Strengths of mdfmonitor

① Difference Both ** FileModificationMonitor ** and ** URLModificationMonitor ** yield an object called ** ModificationObject **, but this object has new Body data and old data, and based on that, it's called ** diff **. Generates a diff string. (I'm using a module called difflib in Python)

ModificationObjectManager History is an integral part of updates, isn't it? ** ModificationObjectManager ** is a class that saves its history. The update object is inserted in the array called o_repository of Manager, and that array becomes the update history as it is.

Installation method

Since it is a Python module, you can use pip and ʻeasy_install`.

``shell $ sudo easy_install mdfmonitor


Or`git`Please use

```shell
$ git clone https://github.com/alice1017/mdfmonitor.git
$ cd mdfmonitor
$ sudo pyton setup.py build install

LICENSE

MIT license

##so

That's why I introduced mdfmonitor. When I searched for it on PYPI, there weren't many modules like this, so I made it again. The terrible English in the README and docstring is by design.

If you say "it is better to design like this" or "there is a bug", please pull or comment on github.

##What you can do with mdfmonitor

Since mdfmonitor is a script that monitors file updates, gitFor those who manage the version with, it is automaticaddAnd automaticcommitCan be implemented.

Recommended Posts

Created a module to monitor file and URL updates
Output a binary dump in binary and revert to a binary file
Upload a file to Dropbox
Read and write a file
Write and read a file
To add a C module to MicroPython ...
Process Splunk execution results using Python and save to a file
Write standard output to a file
Created a class to download and parse XBRL from UFO Catcher
Created a Discord bot to notify you of updates to become a novelist
How to create a config file
[Python scraping] Output the URL and title of the site containing a specific keyword to a text file
[Python] How to read a csv file (read_csv method of pandas module)
Script to create a Mac dictionary file
[Introduction to Pandas] Read a csv file without a column name and give it a column name
Try to get a web page and JSON file using Python's Requests library
I want to drop a file on tkinter and get its path [Tkinter DnD2]
Attempt to launch another .exe and save the console output to a text file
I want to make a music player and file music at the same time
I want to write an element to a file with numpy and check it.
Zip-compress any file with the [shell] command to create a file and delete the original file.
[Python] Concatenate a List containing numbers and write it to an output file.
Save an array of numpy to a wav file using the wave module
How to read a serial number file in a loop, process it, and graph it
How to read a CSV file with Python 2/3
How to disguise a ZIP file as a PNG file
Create a GUI executable file created with tkinter
How to create a JSON file in Python
A memo created in a package and registered in PyPI
Make a chatbot and practice to be popular.
How to add a Python module search path
Output python log to both console and file
To add a module to python put in Julialang
Add query to url parsed url and return to original url
Save the object to a file with pickle
Export Python3 version OpenCV KeyPoint to a file
Load a package created locally with Go Module
I want to write to a file with Python
How to uninstall a module installed using setup.py
How to read a file in a different directory
Created a Python library to write complex comprehensions and reduce in an easy-to-read manner
What to do if pvcreate produces a lot of WARNING and cannot be created
[pyqtgraph] Created a class to display the crosshairs that follow the cursor and their coordinates
[Python] You can save an object to a file by using the pickle module.
[Django] Test to send a file by POST and check the returned context [TDD]
Created a tool to output a sequence diagram from a packet capture file of multiple nodes
A high school student created a real-time language conversion service and pushed it to Github.