urlfix
aims to find all outdated URLs in a given file and fix them.
Supported file formats
urlfix
fixes URLs given a file of the following types:
- MarkDown (.md)
- Plain Text files (.txt)
Installation
The simplest way to install the latest release is as follows:
pip install urlfix
To install the development version:
Open the Terminal/CMD/Git bash/shell and enter
pip install git+https://github.com/Nelson-Gon/urlfix.git
# or for the less stable dev version
pip install git+https://github.com/Nelson-Gon/urlfix.git@dev
Otherwise:
# clone the repo
git clone [email protected]:Nelson-Gon/urlfix.git
cd urlfix
python3 setup.py install
Sample usage
from urlfix.urlfix import *
Create an object of class URLFix
urlfix_object = URLFix("testurls.txt", output_file="replacement.txt")
Replacing URLs
After 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 set verbose
to True
, we get the following output:
urlfix_object.replace_urls()
Found https://www.r-pkg.org/badges/version/manymodelr in testurls.txt, now validating..
Found https://cran.r-project.org/package=manymodelr in testurls.txt, now validating..
https://cran.r-project.org/package=manymodelr replaced with https://cran.r-project.org/web/packages/manymodelr/index.html
in replacement.txt
Found https://tidyverse.org/lifecycle/#maturing in testurls.txt, now validating..
https://tidyverse.org/lifecycle/#maturing replaced with https://lifecycle.r-lib.org/articles/stages.html in
replacement.txt
2 URLs have changed of the 3 links found in testurls.txt
2
To replace silently, simply set verbose to False
(which is the default).
urlfix_object.replace_urls()
2 URLs have changed of the 3 links found in testurls.txt
2
Replacing several files in a directory
To replace several files in a directory, we can use DirURLFix
as follows.
- Instantiate an object of class
DirURLFix
replace_in_dir = DirURLFix("path_to_dir")
- Call
replace_urls
replace_in_dir.replace_urls()
To report any issues, suggestions or improvement, please do so at issues.
If you would like to cite this work, please use:
Nelson Gonzabato (2021) urlfix: Check and Fix Outdated URLs https://github.com/Nelson-Gon/urlfix
Thank you very much.
“Before software can be reusable it first has to be usable.” – Ralph Johnson