From 0a2f97c034073af82f770ef83a5f765b9db00825 Mon Sep 17 00:00:00 2001 From: Akash Mahanty Date: Fri, 16 Oct 2020 22:37:32 +0530 Subject: [PATCH] Update README, drop python 2 support * Drop python 2 support * updated docs * added new docs --- README.md | 84 +++++++++++++++++++++++++++++++++++++++-- setup.py | 4 +- waybackpy/exceptions.py | 2 +- 3 files changed, 82 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c21582b..ec5747d 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,10 @@ Table of contents * [Usage](#usage) * [As a Python package](#as-a-python-package) * [Saving an url](#capturing-aka-saving-an-url-using-save) + * [Retrieving archive](#retrieving-the-archive-for-an-url-using-archive_url) * [Retrieving the oldest archive](#retrieving-the-oldest-archive-for-an-url-using-oldest) * [Retrieving the recent most/newest archive](#retrieving-the-newest-archive-for-an-url-using-newest) + * [Retrieving the JSON response of availability API](#retrieving-the-json-reponse-for-the-avaliblity-api-request) * [Retrieving archive close to a specified year, month, day, hour, and minute](#retrieving-archive-close-to-a-specified-year-month-day-hour-and-minute-using-near) * [Get the content of webpage](#get-the-content-of-webpage-using-get) * [Count total archives for an URL](#count-total-archives-for-an-url-using-total_archives) @@ -37,8 +39,10 @@ Table of contents * [With the Command-line interface](#with-the-command-line-interface) * [Save](#save) - * [Oldest archive](#oldest-archive) - * [Newest archive](#newest-archive) + * [Archive URL](#get-archive-url) + * [Oldest archive URL](#oldest-archive) + * [Newest archive URL](#newest-archive) + * [JSON response of API](#get-json-data-of-avaialblity-api) * [Total archives](#total-number-of-archives) * [Archive near specified time](#archive-near-time) * [Get the source code](#get-the-source-code) @@ -93,6 +97,26 @@ https://web.archive.org/web/20200504141153/https://github.com/akamhy/waybackpy Try this out in your browser @ +#### Retrieving the archive for an URL using archive_url + +```python +import waybackpy + +archive_url = waybackpy.Url( + + "https://www.google.com/", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:40.0) Gecko/20100101 Firefox/40.0" +).archive_url + +print(archive_url) +``` + +```bash +https://web.archive.org/web/20201016153320/https://www.google.com/ +``` + +Try this out in your browser @ + #### Retrieving the oldest archive for an URL using oldest() ```python @@ -134,6 +158,26 @@ https://web.archive.org/web/20200714013225/https://www.facebook.com/ Try this out in your browser @ +#### Retrieving the JSON reponse for the avaliblity API request + +```python +import waybackpy + +json_dict = waybackpy.Url( + + "https://www.google.com/", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:40.0) Gecko/20100101 Firefox/40.0" +).JSON + +print(json_dict) +``` + +```javascript +{'url': 'https://www.google.com/', 'archived_snapshots': {'closest': {'available': True, 'url': 'http://web.archive.org/web/20201016153320/https://www.google.com/', 'timestamp': '20201016153320', 'status': '200'}}} +``` + +Try this out in your browser @ + #### Retrieving archive close to a specified year, month, day, hour, and minute using near() ```python @@ -286,6 +330,15 @@ https://web.archive.org/web/20200719062108/https://en.wikipedia.org/wiki/Social_ Try this out in your browser @ +#### Get archive URL + +```bash +$ waybackpy --url "https://en.wikipedia.org/wiki/SpaceX" --user_agent "my-unique-user-agent" --archive_url +https://web.archive.org/web/20201007132458/https://en.wikipedia.org/wiki/SpaceX +``` + +Try this out in your browser @ + #### Oldest archive ```bash @@ -304,6 +357,20 @@ https://web.archive.org/web/20200606044708/https://en.wikipedia.org/wiki/YouTube Try this out in your browser @ +#### Get JSON data of avaialblity API + +```bash +$ waybackpy --url "https://en.wikipedia.org/wiki/SpaceX" --user_agent "my-unique-user-agent" --json + +``` + +```javascript +{'archived_snapshots': {'closest': {'timestamp': '20201007132458', 'status': '200', 'available': True, 'url': 'http://web.archive.org/web/20201007132458/https://en.wikipedia.org/wiki/SpaceX'}}, 'url': 'https://en.wikipedia.org/wiki/SpaceX'} + +``` + +Try this out in your browser @ + #### Total number of archives ```bash @@ -365,12 +432,21 @@ waybackpy --url akamhy.github.io --user_agent "my-user-agent" --known_urls --sub Try this out in your browser @ ## Tests - [Here](https://github.com/akamhy/waybackpy/tree/master/tests) +To run tests locally: +```bash +pip install -U pytest +pip install codecov +pip install pytest pytest-cov +cd tests +pytest --cov=../waybackpy +python -m codecov #For reporting coverage on Codecov +``` + ## Dependency -None, just python standard libraries (re, json, urllib, argparse and datetime). Both python 2 and 3 are supported :) +None, just pre-installed [python standard libraries](https://docs.python.org/3/library/). ## Packaging diff --git a/setup.py b/setup.py index ef11e33..e57670b 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ setup( download_url = 'https://github.com/akamhy/waybackpy/archive/2.1.9.tar.gz', keywords = ['wayback', 'archive', 'archive website', 'wayback machine', 'Internet Archive'], install_requires=[], - python_requires= ">=2.7", + python_requires= ">=3.2", classifiers=[ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', @@ -30,8 +30,6 @@ setup( 'Topic :: Software Development :: Build Tools', 'License :: OSI Approved :: MIT License', 'Programming Language :: Python', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.2', 'Programming Language :: Python :: 3.3', diff --git a/waybackpy/exceptions.py b/waybackpy/exceptions.py index 69ddc20..c2f0042 100644 --- a/waybackpy/exceptions.py +++ b/waybackpy/exceptions.py @@ -2,5 +2,5 @@ class WaybackError(Exception): """ - Raised when API Service error. + Raised when Wayback Machine API Service is unreachable/down. """