Package: urlfix
urlfix: Check and Fix Outdated URLsurlfixaims to find all outdated URLs in a given file and fix them.Features ListCommandline and programmer-friendly modes.Replace outdated URLs/links in a single fileReplace outdated URLs/links in a directoryReplace outdated URLs/links in the same file or in the same files in a directory i.e. inplace.Replace outdated links in files in nested directoriesReplace outdated links in files in sub-nested directoriesSupported file formatsurlfixfixes URLs given a file of the following types:MarkDown (.md)Plain Text files (.txt)RMarkdown (.rmd)ReStructured Text (.rst)PDF (.pdf)Word (.docx)ODF (.odf)InstallationThe simplest way to install the latest release is as follows:pipinstallurlfixTo install the development version:Open the Terminal/CMD/Git bash/shell and enterpipinstallgit+https://github.com/Nelson-Gon/urlfix.git# or for the less stable dev versionpipinstallgit+https://github.com/Nelson-Gon/urlfix.git@devOtherwise:# clone the repogitclonegit@github.com:Nelson-Gon/urlfix.gitcdurlfix
python3setup.pyinstallSample usageScript ModeTo use at the commandline, please use:python-murlfix--mode"f"--verbose1--inplace1--inpathmyfile.mdIf not replacing within the same file, then:python-murlfix--mode"f"--verbose1--inplace0--inpathmyfile.md--output-filemyoutputfile.mdTo get help:python-murlfix-h#usage: main.py [-h] -m MODE -in INPUT_FILE [-o OUTPUT_FILE] -v {False,false,0,True,true,1} -i {False,false,0,True,true,1}##optional arguments:#  -h, --help            show this help message and exit#  -m MODE, --mode MODE  Mode to use. One of f for file or d for directory#  -in INPUT_FILE, --input-file INPUT_FILE#                        Input file for which link updates are required.#  -o OUTPUT_FILE, --output-file OUTPUT_FILE#                        Output file to write to. Optional, only necessary if not replacing inplace#  -v {False,false,0,True,true,1}, --verbose {False,false,0,True,true,1}#                        String to control verbosity. Defaults to True.#  -i {False,false,0,True,true,1}, --inplace {False,false,0,True,true,1}#                        Should links be replaced inplace? This should be safe but to be sure, test with an output file first.Programmer-Friendly Modefromurlfix.urlfiximportURLFixfromurlfix.dirurlfiximportDirURLFixCreate an object of class URLFixurlfix_object=URLFix("testfiles/testurls.txt",output_file="replacement.txt")Replacing URLsAfter creating our object, we can replace outdated URLs as follows:urlfix_object.replace_urls(verbose=1)The above uses default arguments and will not replace a file inplace. This is a safety mechanism to ensure one does not
damage their files.Since we setverbosetoTrue, we get the following output:urlfix_object.replace_urls()To replace silently, simply set verbose toFalse(which is the default).urlfix_object.replace_urls()If there are URLs known to be valid, pass these to thecorrect_urlsargument to save some time.urlfix_object.replace_urls(correct_urls=[urls_here])# Use a Sequence eg tuple, list, etcReplacing several files in a directoryTo replace several files in a directory, we can useDirURLFixas follows.Instantiate an object of classDirURLFixreplace_in_dir=DirURLFix("path_to_dir")Callreplace_urlsreplace_in_dir.replace_urls()Recursively replacing links in nested directoriesTo replace outdated links in several files located in several directories, we setrecursivetoTrue.
Currently, replacing links in directories nested within nested directories is not (yet) supported.recursive_object=DirURLFix("path_to_root_directory",recursive=True)We can then proceed as aboverecursive_object.replace_urls()# provide other arguments as you may wish.To report any issues, suggestions or improvement, please do so atissues.If you would like to cite this work, please use:Nelson Gonzabato (2021) urlfix: Check and Fix Outdated URLshttps://github.com/Nelson-Gon/urlfixThank you very much.“Before software can be reusable it first has to be usable.” – Ralph Johnson