Update wrapper.py

This commit is contained in:
akamhy 2020-05-07 16:24:33 +05:30 committed by GitHub
parent 01a7c591ad
commit 0ca6710334
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,13 +18,18 @@ def url_check(url):
def clean_url(url): def clean_url(url):
return str(url).strip().replace(" ","_") return str(url).strip().replace(" ","_")
def wayback_timestamp(year, month, day, hour, minute): def wayback_timestamp(**kwargs):
year = str(year) return (
month = str(month).zfill(2) str(kwargs["year"])
day = str(day).zfill(2) +
hour = str(hour).zfill(2) str(kwargs["month"]).zfill(2)
minute = str(minute).zfill(2) +
return (year+month+day+hour+minute) str(kwargs["day"]).zfill(2)
+
str(kwargs["hour"]).zfill(2)
+
str(kwargs["minute"]).zfill(2)
)
def save(url, UA=default_UA): def save(url, UA=default_UA):
base_save_url = "https://web.archive.org/save/" base_save_url = "https://web.archive.org/save/"
@ -87,7 +92,7 @@ def near(
UA=default_UA, UA=default_UA,
): ):
url_check(url) url_check(url)
timestamp = wayback_timestamp(year,month,day,hour,minute) timestamp = wayback_timestamp(year=year,month=month,day=day,hour=hour,minute=minute)
request_url = "https://archive.org/wayback/available?url=%s&timestamp=%s" % (clean_url(url), str(timestamp)) request_url = "https://archive.org/wayback/available?url=%s&timestamp=%s" % (clean_url(url), str(timestamp))
hdr = { 'User-Agent' : '%s' % UA } hdr = { 'User-Agent' : '%s' % UA }
req = Request(request_url, headers=hdr) # nosec req = Request(request_url, headers=hdr) # nosec