Skip to content

Commit

Permalink
improve Ctrl-C behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
clouds56 committed Apr 6, 2017
1 parent d8c58cd commit 134b83a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions download.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import mistune
import bs4 as BeautifulSoup
import socket
import time

def download_pdf(link, location, name):
try:
Expand All @@ -20,6 +21,7 @@ def download_pdf(link, location, name):
raise
except socket.timeout:
print(" ".join(("can't download", link, "due to connection timeout!")) )
raise

def clean_pdf_link(link):
if 'arxiv' in link:
Expand Down Expand Up @@ -100,6 +102,13 @@ def shorten_title(title):
fullname = '.'.join((name, ext))
if not os.path.exists('/'.join((current_directory, fullname)) ):
download_pdf(link, current_directory, '.'.join((name, ext)))
except KeyboardInterrupt:
try:
print("Press Ctrl-C in 1 second to quit")
time.sleep(1)
except KeyboardInterrupt:
print("Cancelling..")
break
except:
failures.append(point.text)

Expand Down

0 comments on commit 134b83a

Please sign in to comment.