Skip to content

Commit

Permalink
Added regex for checking book URL
Browse files Browse the repository at this point in the history
  • Loading branch information
holzkohlengrill committed Aug 25, 2021
1 parent ecda0db commit 774ebb6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions safaribooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
PROFILE_URL = SAFARI_BASE_URL + "/profile/"

# DEBUG
USE_PROXY = False
PROXIES = {"https": "https://127.0.0.1:8080"}
USE_PROXY = True
PROXIES = {"https": "http://de001-surf.zone2.proxy.allianz:8080"}


class Display:
Expand Down Expand Up @@ -317,7 +317,7 @@ def __init__(self, args):
self.session = requests.Session()
if USE_PROXY: # DEBUG
self.session.proxies = PROXIES
self.session.verify = False
self.session.verify = True

self.session.headers.update(self.HEADERS)

Expand Down Expand Up @@ -1110,7 +1110,14 @@ def create_epub(self):
arguments.error("invalid option: `--no-cookies` is valid only if you use the `--cred` option")

if len(args_parsed.bookid) > 0:
bookID = args_parsed.bookid.split("/")[-1] # Only get book ID from URL
bookid_regex = r"['\"]*http[s]?://[a-zA-Z0-9.\-/]+(\d{10,15})/*['\"]*" # Matches book URL
pattern = re.compile(bookid_regex)
match = re.search(pattern, args_parsed.bookid)
if match:
bookID = match.group(1)
else:
bookID = None
arguments.error("Invalid book ID or URL")
if str.isdecimal(bookID):
args_parsed.bookid = bookID
else:
Expand Down

0 comments on commit 774ebb6

Please sign in to comment.