Compare commits

...

5 Commits
2.1.3 ... 2.1.4

Author SHA1 Message Date
4dcda94cb0 v2.1.4 2020-07-24 01:03:44 +05:30
09f59b0182 v2.1.4 2020-07-24 01:03:04 +05:30
ed24184b99 Remove duplicate get response method 2020-07-24 00:57:22 +05:30
56bef064b1 only test save on >3.7 2020-07-23 20:51:46 +05:30
44bb2cf5e4 some cli tests 2020-07-23 20:44:14 +05:30
4 changed files with 49 additions and 17 deletions

View File

@ -19,7 +19,7 @@ setup(
author = about['__author__'],
author_email = about['__author_email__'],
url = about['__url__'],
download_url = 'https://github.com/akamhy/waybackpy/archive/2.1.3.tar.gz',
download_url = 'https://github.com/akamhy/waybackpy/archive/2.1.4.tar.gz',
keywords = ['wayback', 'archive', 'archive website', 'wayback machine', 'Internet Archive'],
install_requires=[],
python_requires= ">=2.7",

43
tests/test_cli.py Normal file
View File

@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
import sys
import os
import pytest
import argparse
sys.path.append("..")
import waybackpy.cli as cli # noqa: E402
from waybackpy.wrapper import Url # noqa: E402
if sys.version_info > (3, 7):
def test_save():
obj = Url("https://pypi.org/user/akamhy/", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 (KHTML, like Gecko) Version/8.0.8 Safari/600.8.9")
cli._save(obj)
else:
pass
def test_get():
args = argparse.Namespace(get='oldest')
obj = Url("https://pypi.org/user/akamhy/", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 (KHTML, like Gecko) Version/8.0.8 Safari/600.8.9")
cli._get(obj, args)
args = argparse.Namespace(get='newest')
cli._get(obj, args)
args = argparse.Namespace(get='url')
cli._get(obj, args)
if sys.version_info > (3, 7):
args = argparse.Namespace(get='save')
cli._get(obj, args)
else:
pass
def test_oldest():
obj = Url("https://pypi.org/user/akamhy/", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 (KHTML, like Gecko) Version/8.0.8 Safari/600.8.9")
cli._oldest(obj)
def test_newest():
obj = Url("https://pypi.org/user/akamhy/", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 (KHTML, like Gecko) Version/8.0.8 Safari/600.8.9")
cli._newest(obj)
def test_near():
args = argparse.Namespace(year=2020, month=6, day=1, hour=1, minute=1)
obj = Url("https://pypi.org/user/akamhy/", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 (KHTML, like Gecko) Version/8.0.8 Safari/600.8.9")
cli._near(obj, args)

View File

@ -3,7 +3,7 @@
__title__ = "waybackpy"
__description__ = "A Python library that interfaces with the Internet Archive's Wayback Machine API. Archive pages and retrieve archived pages easily."
__url__ = "https://akamhy.github.io/waybackpy/"
__version__ = "2.1.3"
__version__ = "2.1.4"
__author__ = "akamhy"
__author_email__ = "akash3pro@gmail.com"
__license__ = "MIT"

View File

@ -51,10 +51,12 @@ def _get_response(req):
try:
response = urlopen(req) # nosec
except Exception as e:
raise WaybackError(e)
exc = WaybackError("Error while retrieving %s" % req.full_ur
)
exc.__cause__ = e
raise exc
return response
class Url:
"""waybackpy Url object"""
@ -108,19 +110,6 @@ class Url:
encoding = "UTF-8"
return response.read().decode(encoding.replace("text/html", "UTF-8", 1))
def get_response(self, req):
"""Get response for the supplied request."""
try:
response = urlopen(req) #nosec
except Exception:
try:
response = urlopen(req) #nosec
except Exception as e:
exc = WaybackError("Error while retrieving %s" % req.full_url)
exc.__cause__ = e
raise exc
return response
def near(self, year=None, month=None, day=None, hour=None, minute=None):
""" Return the closest Wayback Machine archive to the time supplied.
Supported params are year, month, day, hour and minute.