Skip to content

Instantly share code, notes, and snippets.

@eggplants
Last active July 15, 2020 12:48
Show Gist options
  • Save eggplants/138ce2ee76617023c79089460b296458 to your computer and use it in GitHub Desktop.
Save eggplants/138ce2ee76617023c79089460b296458 to your computer and use it in GitHub Desktop.
import time
import savepagenow as save
def measure(f, *arg):
s=time.time()
try:
print(f(*arg))
except save.exceptions.WaybackRuntimeError as e:
print(e)
print(f"{f.__name__}: {time.time()-s} sec.")
URL=[
'example.com',
'github.com',
'twitter.com',
'https://app.diagrams.net/',
'https://github.com/97-things/97-things-every-programmer-should-know/blob/master/en/SUMMARY.md'
]
def main():
for url in URL:
for fun in (save.capture, save.capture_or_cache):
measure(fun, url)
time.sleep(10)
if __name__ == '__main__':
main()
import time
import savepagenow as save
def measure(f, *arg):
s=time.time()
# try:
print(f(*arg))
# except save.exceptions.WaybackRuntimeError as e:
# print(e)
print(f"{f.__name__}: {time.time()-s} sec.")
URL=[
'example.com',
'github.com',
'twitter.com',
'https://app.diagrams.net/',
'https://github.com/97-things/97-things-every-programmer-should-know/blob/master/en/SUMMARY.md'
]
def main():
for url in URL:
for fun in (save.capture, save.capture_or_cache):
measure(fun, url)
time.sleep(10)
if __name__ == '__main__':
main()
@eggplants
Copy link
Author

eggplants commented Jul 15, 2020

# ALLOK
{'Server': 'nginx/1.15.8', 'Date': 'Wed, 15 Jul 2020 12:16:19 GMT', 'Content-Type': 'text/html', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache'}
capture: 108.6826012134552 sec.
{'Server': 'nginx/1.15.8', 'Date': 'Wed, 15 Jul 2020 12:17:33 GMT', 'Content-Type': 'text/html', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache'}
capture_or_cache: 64.48632478713989 sec.
{'Server': 'nginx/1.15.8', 'Date': 'Wed, 15 Jul 2020 12:20:07 GMT', 'Content-Type': 'text/html', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache'}
capture: 143.92051649093628 sec.
('https://web.archive.org/web/20200715122013/https://github.com/', True)
capture_or_cache: 237.84660172462463 sec.
{'Server': 'nginx/1.15.8', 'Date': 'Wed, 15 Jul 2020 12:26:16 GMT', 'Content-Type': 'text/html', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache'}
capture: 110.27080726623535 sec.
{'Server': 'nginx/1.15.8', 'Date': 'Wed, 15 Jul 2020 12:28:57 GMT', 'Content-Type': 'text/html', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache'}
capture_or_cache: 151.9405698776245 sec.
https://web.archive.org/web/20200715123237/https://app.diagrams.net/
capture: 232.71794438362122 sec.
{'Server': 'nginx/1.15.8', 'Date': 'Wed, 15 Jul 2020 12:34:45 GMT', 'Content-Type': 'text/html', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache'}
capture_or_cache: 95.27539658546448 sec.
{'Server': 'nginx/1.15.8', 'Date': 'Wed, 15 Jul 2020 12:36:51 GMT', 'Content-Type': 'text/html', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache'}
capture: 115.47913384437561 sec.
{'Server': 'nginx/1.15.8', 'Date': 'Wed, 15 Jul 2020 12:39:05 GMT', 'Content-Type': 'text/html', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache'}
capture_or_cache: 124.48301815986633 sec.

@eggplants
Copy link
Author

eggplants commented Jul 15, 2020

# NO CATCH ERR 
Traceback (most recent call last):
  File "test_save.py", line 28, in <module>
    main()
  File "test_save.py", line 24, in main
    measure(fun, url)
  File "test_save.py", line 8, in measure
    print(f(*arg))
  File "/home/eggplants/.pyenv/versions/3.8.0/lib/python3.8/site-packages/savepagenow/api.py", line 52, in capture
    raise WaybackRuntimeError(response.headers)
savepagenow.exceptions.WaybackRuntimeError: {'Server': 'nginx/1.15.8', 'Date': 'Wed, 15 Jul 2020 12:46:26 GMT', 'Content-Type': 'text/html', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache'}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment