Added error checking - previously a wrong password did not lead to an error.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Tue, 20 Oct 2015 21:16:51 +0000 (23:16 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Tue, 20 Oct 2015 21:16:51 +0000 (23:16 +0200)
bob_download.py

index b3b67b2b68e158609c13db1cc9f0007e1fa54b7e..3941e7aa78c30321c1716b7b8edc16d41f710950 100644 (file)
@@ -33,6 +33,7 @@ def main(username, password, destdir, csv_format):
 
     # load login page
     response = session.get('https://rechnung.bob.at/')
+    assert response.ok
     html = BeautifulSoup(response.text, 'html.parser')
 
     # fill out login form (name='asmpform') with username=<phone number> and password
@@ -45,6 +46,10 @@ def main(username, password, destdir, csv_format):
 
     # load overview page
     response = session.post(form['action'], data=fields)
+    assert response.ok
+    assert 'invalid KKW response' not in response.text
+    html = BeautifulSoup(response.text, 'html.parser')
+    assert html.find('a', title="ausloggen") is not None
 
     # reload overview page rechnung.bob.at - that makes the URLs in the page much prettier
     # previously:
@@ -52,6 +57,7 @@ def main(username, password, destdir, csv_format):
     # same after reload:
     # '/bill/pdf/Rechnungskopie_1509_523260091_1.pdf?bsn=61'
     response = session.get(response.url)
+    assert response.ok
     html = BeautifulSoup(response.text, 'html.parser')
 
     # Download PDFs
@@ -65,7 +71,7 @@ def main(username, password, destdir, csv_format):
         filepath = os.path.join(destdir, filename)
         if not os.path.exists(filepath):
             response = session.get(urljoin(response.url, url))
-            assert response.status_code == 200
+            assert response.ok
             with open(filepath, 'wb') as file:
                 file.write(response.content)
 
@@ -76,7 +82,7 @@ def main(username, password, destdir, csv_format):
     for link in links:
         url = link['href']
         response = session.get(urljoin(response.url, url))
-        assert response.status_code == 200
+        assert response.ok
         assert 'OBP.utils.reloadAfterDelay("/bill.ctn.cdr.set.obp",5);' in response.text
         time.sleep(5) # OBP.utils.reloadAfterDelay("/bill.ctn.cdr.set.obp",5);
         response = session.get(urljoin(response.url, 'bill.ctn.cdr.set.obp'))
@@ -84,7 +90,7 @@ def main(username, password, destdir, csv_format):
         html = BeautifulSoup(response.text, 'html.parser')
         assert html.find('a', id='link_csv_download') is not None
         response = session.get('https://rechnung.bob.at/download.table.obp?fmt={}&table=obp.calls.table'.format(csv_format))
-        assert response.status_code == 200
+        assert response.ok
         filename = response.headers['Content-Disposition'].split('=')[1] # e.g. 'EVN_1509_523260091_1_069911934859.txt'
         assert filename.startswith('EVN_')
         filepath = os.path.join(destdir, filename)