Skip to content

Fix download if document is not in scope or has no attachments #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions vbscraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,22 @@ def download_document(self, document, destinations):
)
page_number = li.text.strip()

if not page_number == '1':
raise RuntimeError('Postbox does not start with page 1')
if not page_number:
raise RuntimeError('Postbox current page number not found')

if not document.postbox_page == page_number:
# get postbox page
if self.verbose:
print("Access postbox page {}".format(document.postbox_page))

while not li.text.strip() == document.postbox_page:
li = li.find_next_sibling()
if li.find_next_sibling():
li = li.find_next_sibling()
else: # page not in current scope, move on to last found page and look again
self.postbox_url = li.a['href']
self.download_document(document, destinations)
return


page_url = li.a['href']
r = self.s.get(self.base_url + page_url)
Expand All @@ -237,6 +243,9 @@ def download_document(self, document, destinations):
'a', title='Anhang öffnen'
)

if not attachment_a: # message in postbox has no attachment to download
return

attachment_url = attachment_a['href']

filename = attachment_a.text
Expand Down