From a44fbc75c81e4a904732a4d9e6c33263b23a08df Mon Sep 17 00:00:00 2001 From: Daniel Valenzuela Date: Thu, 15 Oct 2020 17:21:09 -0400 Subject: [PATCH] fixed bug with len() of url() --- Untitled.ipynb | 111 +++++++++++++++++++++++++++++++++++++++++++ waybackpy/wrapper.py | 9 ++-- 2 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 Untitled.ipynb diff --git a/Untitled.ipynb b/Untitled.ipynb new file mode 100644 index 0000000..d01ae24 --- /dev/null +++ b/Untitled.ipynb @@ -0,0 +1,111 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The autoreload extension is already loaded. To reload it, use:\n", + " %reload_ext autoreload\n" + ] + } + ], + "source": [ + "%load_ext autoreload\n", + "%autoreload 2\n", + "from waybackpy import wrapper" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "https://web.archive.org/web/20201015031659/https://www.google.com/\n" + ] + } + ], + "source": [ + "user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36'\n", + "url = 'https://www.google.com/'\n", + "\n", + "new_archive_url = wrapper.Url(user_agent=user_agent, url=url).newest()\n", + "print(new_archive_url)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(wrapper.Url(user_agent=user_agent, url='https://medium.com/@danvalen1'))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(timestamp)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "save" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "learn-env", + "language": "python", + "name": "learn-env" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.10" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/waybackpy/wrapper.py b/waybackpy/wrapper.py index 49e5f30..20bbe90 100644 --- a/waybackpy/wrapper.py +++ b/waybackpy/wrapper.py @@ -80,9 +80,12 @@ class Url: return "%s" % self.archive_url def __len__(self): - diff = datetime.utcnow() - self.timestamp - return diff.days - + if self.timestamp != None: + diff = datetime.utcnow() - self.timestamp + return diff.days + else + return None + def _url_check(self): """Check for common URL problems.""" if "." not in self.url: