From f881705d00bf47b5bf0c58808efe29eecba2226c Mon Sep 17 00:00:00 2001 From: Akash <64683866+akamhy@users.noreply.github.com> Date: Fri, 26 Jun 2020 15:48:01 +0530 Subject: [PATCH] detecet python version whith sys.version_info (#9) --- waybackpy/wrapper.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/waybackpy/wrapper.py b/waybackpy/wrapper.py index c172100..894b048 100644 --- a/waybackpy/wrapper.py +++ b/waybackpy/wrapper.py @@ -1,15 +1,21 @@ # -*- coding: utf-8 -*- + +import sys import json from datetime import datetime from waybackpy.exceptions import TooManyArchivingRequests, ArchivingNotAllowed, PageNotSaved, ArchiveNotFound, UrlNotFound, BadGateWay, InvalidUrl, WaybackUnavailable -try: + +version = (3, 0) +cur_version = sys.version_info + + +if cur_version >= version: # If the python ver >= 3 from urllib.request import Request, urlopen from urllib.error import HTTPError, URLError -except ImportError: +else: # For python2.x from urllib2 import Request, urlopen, HTTPError, URLError - -default_UA = "waybackpy python package" +default_UA = "waybackpy python package ; ( https://github.com/akamhy/waybackpy )" def url_check(url): if "." not in url: