mirror of
https://github.com/Noettore/fattureCCSR.git
synced 2025-10-14 19:26:39 +02:00
Added try except block to check for connectivity errors
This commit is contained in:
@@ -6,13 +6,21 @@ import tempfile
|
||||
import openpyxl
|
||||
import PyPDF2
|
||||
import wx
|
||||
import requests
|
||||
|
||||
def download_input_file(parent):
|
||||
"""download input file"""
|
||||
start_date = parent.start_date_picker.GetValue().Format("%d/%m/%Y")
|
||||
end_date = parent.end_date_picker.GetValue().Format("%d/%m/%Y")
|
||||
input_file_url = 'https://report.casadicurasanrossore.it:8443/reportserver?/STAT_FATTURATO_CTERZI&dataI='+start_date+'&dataF='+end_date+'&rs:Format=EXCELOPENXML'
|
||||
downloaded_input_file = parent.session.get(input_file_url)
|
||||
try:
|
||||
downloaded_input_file = parent.session.get(input_file_url)
|
||||
except requests.exceptions.RequestException:
|
||||
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr(wx.RED, font=wx.Font(wx.FontInfo(8).Bold())))
|
||||
parent.log_dialog.log_text.AppendText("ERRORE: impossibile connettersi al portale CCSR.")
|
||||
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr())
|
||||
wx.Yield()
|
||||
return
|
||||
if downloaded_input_file.status_code != 200:
|
||||
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr(wx.RED, font=wx.Font(wx.FontInfo(8).Bold())))
|
||||
parent.log_dialog.log_text.AppendText("ERRORE: impossibile scaricare il file di input.\nControllare la connessione ad internet e l'operatività del portale CCSR. Code %d\n" % downloaded_input_file.status_code)
|
||||
@@ -73,28 +81,35 @@ def download_invoices(parent):
|
||||
downloaded_count = 0
|
||||
|
||||
for invoice_id, invoice in invoices.items():
|
||||
resp = parent.session.get(invoice["url"])
|
||||
if resp.status_code == 200:
|
||||
with open(tmp_dir+"/"+invoice_id+".pdf", "wb") as output_file:
|
||||
output_file.write(resp.content)
|
||||
invoice["path"] = output_file.name
|
||||
try:
|
||||
PyPDF2.PdfFileReader(open(invoice["path"], "rb"))
|
||||
except (PyPDF2.utils.PdfReadError, OSError):
|
||||
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr(wx.RED, font=wx.Font(wx.FontInfo(8).Bold())))
|
||||
parent.log_dialog.log_text.AppendText("Errore: fattura %s corrotta!\n" % invoice_id)
|
||||
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr())
|
||||
wx.Yield()
|
||||
invoice["good"] = False
|
||||
else:
|
||||
downloaded_count += 1
|
||||
if parent.verbose:
|
||||
parent.log_dialog.log_text.AppendText("%d/%d scaricata fattura %s in %s\n" % (downloaded_count, invoices_count, invoice_id, invoice["path"]))
|
||||
try:
|
||||
resp = parent.session.get(invoice["url"])
|
||||
if resp.status_code == 200:
|
||||
with open(tmp_dir+"/"+invoice_id+".pdf", "wb") as output_file:
|
||||
output_file.write(resp.content)
|
||||
invoice["path"] = output_file.name
|
||||
try:
|
||||
PyPDF2.PdfFileReader(open(invoice["path"], "rb"))
|
||||
except (PyPDF2.utils.PdfReadError, OSError):
|
||||
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr(wx.RED, font=wx.Font(wx.FontInfo(8).Bold())))
|
||||
parent.log_dialog.log_text.AppendText("Errore: fattura %s corrotta!\n" % invoice_id)
|
||||
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr())
|
||||
wx.Yield()
|
||||
invoice["good"] = True
|
||||
else:
|
||||
invoice["good"] = False
|
||||
else:
|
||||
downloaded_count += 1
|
||||
if parent.verbose:
|
||||
parent.log_dialog.log_text.AppendText("%d/%d scaricata fattura %s in %s\n" % (downloaded_count, invoices_count, invoice_id, invoice["path"]))
|
||||
wx.Yield()
|
||||
invoice["good"] = True
|
||||
else:
|
||||
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr(wx.RED, font=wx.Font(wx.FontInfo(8).Bold())))
|
||||
parent.log_dialog.log_text.AppendText("Errore: impossibile scaricare fattura %s: %d\n" % (invoice_id, resp.status_code))
|
||||
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr())
|
||||
wx.Yield()
|
||||
invoice["good"] = False
|
||||
except requests.exceptions.RequestException:
|
||||
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr(wx.RED, font=wx.Font(wx.FontInfo(8).Bold())))
|
||||
parent.log_dialog.log_text.AppendText("Errore: impossibile scaricare fattura %s: %d\n" % (invoice_id, resp.status_code))
|
||||
parent.log_dialog.log_text.AppendText("Errore: impossibile scaricare fattura %s: errore di connessione\n" % invoice_id)
|
||||
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr())
|
||||
wx.Yield()
|
||||
invoice["good"] = False
|
||||
|
@@ -5,6 +5,7 @@ import sys
|
||||
import getopt
|
||||
import subprocess
|
||||
import atexit
|
||||
from requests.models import RequestField
|
||||
import wx
|
||||
import wx.adv
|
||||
import requests
|
||||
@@ -284,13 +285,17 @@ class LoginDialog(wx.Dialog):
|
||||
if self.username.GetValue() not in ("", None) and self.password.GetValue() not in ("", None):
|
||||
session = self.GetParent().session
|
||||
session.auth = requests_ntlm.HttpNtlmAuth("sr\\"+self.username.GetValue(), self.password.GetValue())
|
||||
if session.get('https://report.casadicurasanrossore.it:8443/Reports/browse/').status_code == 200:
|
||||
self.logged_in = True
|
||||
self.username.SetValue('')
|
||||
self.password.SetValue('')
|
||||
self.Close()
|
||||
else:
|
||||
self.error_lbl.SetLabel("Errore: credenziali errate")
|
||||
try:
|
||||
login = session.get('https://report.casadicurasanrossore.it:8443/Reports/browse/')
|
||||
if login.status_code == 200:
|
||||
self.logged_in = True
|
||||
self.username.SetValue('')
|
||||
self.password.SetValue('')
|
||||
self.Close()
|
||||
else:
|
||||
self.error_lbl.SetLabel("Errore: credenziali errate")
|
||||
except requests.exceptions.RequestException:
|
||||
self.error_lbl.SetLabel("Errore: impossibile connettersi")
|
||||
else:
|
||||
self.error_lbl.SetLabel("Errore: credenziali mancanti")
|
||||
|
||||
|
@@ -7,16 +7,24 @@ import tempfile
|
||||
import lxml.etree
|
||||
import unidecode
|
||||
import wx
|
||||
import requests
|
||||
|
||||
def download_input_file(parent):
|
||||
"""download input file from CCSR SSRS web service"""
|
||||
start_date = parent.start_date_picker.GetValue().Format("%d/%m/%Y")
|
||||
end_date = parent.end_date_picker.GetValue().Format("%d/%m/%Y")
|
||||
input_file_url = 'https://report.casadicurasanrossore.it:8443/reportserver?/STAT_FATTURATO_CTERZI&dataI='+start_date+'&dataF='+end_date+'&rs:Format=XML'
|
||||
downloaded_input_file = parent.session.get(input_file_url)
|
||||
try:
|
||||
downloaded_input_file = parent.session.get(input_file_url)
|
||||
except requests.exceptions.RequestException:
|
||||
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr(wx.RED, font=wx.Font(wx.FontInfo(8).Bold())))
|
||||
parent.log_dialog.log_text.AppendText("ERRORE: impossibile connettersi al portale CCSR.")
|
||||
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr())
|
||||
wx.Yield()
|
||||
return None
|
||||
if downloaded_input_file.status_code != 200:
|
||||
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr(wx.RED, font=wx.Font(wx.FontInfo(8).Bold())))
|
||||
parent.log_dialog.log_text.AppendText("ERRORE: impossibile scaricare il file di input.\nControllare la connessione ad internet e l'operatività del portale CCSR. Code %d\n" % downloaded_input_file.status_code)
|
||||
parent.log_dialog.log_text.AppendText("ERRORE: impossibile scaricare il file di input.\nCode %d\n" % downloaded_input_file.status_code)
|
||||
parent.log_dialog.log_text.SetDefaultStyle(wx.TextAttr())
|
||||
wx.Yield()
|
||||
return None
|
||||
|
Reference in New Issue
Block a user