Skip to content
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

Enhanced logging #41

Merged
merged 9 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
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
Binary file modified images/batch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/single.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
390 changes: 385 additions & 5 deletions src/VATValidation.fbp

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions src/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
import settings

# import common libraries
import logging
import json
import pandas as pd

logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s')
import logging_config # Setup the logging # noqa: F401
import logging

logger = logging.getLogger(__name__)

columns = ["key1", "key2", "ownvat", "foreignvat", "company", "street", "zip", "town"]

Expand Down Expand Up @@ -50,7 +52,7 @@ def validatebatch(inputfile, outputfile="", type="vies", lang="en"):
resultcode = processjson(inputfile, outputfile, type, lang)
return resultcode
case _:
print("Unsupported file format")
logger.error("Unsupported file format")
return 127


Expand Down Expand Up @@ -96,7 +98,7 @@ def processcsv(inputfile, outputfile, type, lang):
dataframe = pd.DataFrame(results)

# save the dateframe to a csv file
dataframe.to_csv(outputfile, index=False, header=False)
dataframe.to_csv(outputfile, index=False, header=False, sep=settings.load_value_from_json_file("delimiter"))

return 0

Expand Down Expand Up @@ -138,7 +140,7 @@ def processxlsx(inputfile, outputfile, type, lang):
# load the results into a DataFrame
dataframe = pd.DataFrame(results)

# save the dateframe to a csv file
# save the dateframe to a xlsx file
dataframe.to_excel(outputfile, index=False, header=False)

return 0
Expand Down
48 changes: 45 additions & 3 deletions src/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ def __init__( self, parent ):
self.panelBatch.SetSizer( fgSizer3 )
self.panelBatch.Layout()
fgSizer3.Fit( self.panelBatch )
self.m_notebook3.AddPage( self.panelBatch, _(u"Batch"), True )
self.m_notebook3.AddPage( self.panelBatch, _(u"Batch"), False )
self.panelConfig = wx.Panel( self.m_notebook3, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
fgSizer31 = wx.FlexGridSizer( 0, 2, 0, 0 )
fgSizer31 = wx.FlexGridSizer( 0, 3, 0, 0 )
fgSizer31.AddGrowableCol( 1 )
fgSizer31.SetFlexibleDirection( wx.BOTH )
fgSizer31.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
Expand All @@ -211,6 +211,9 @@ def __init__( self, parent ):
self.textCtrlConfigOwnVat = wx.TextCtrl( self.panelConfig, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
fgSizer31.Add( self.textCtrlConfigOwnVat, 0, wx.ALL, 5 )


fgSizer31.Add( ( 0, 0), 1, wx.EXPAND, 5 )

self.staticTextConfigInterface = wx.StaticText( self.panelConfig, wx.ID_ANY, _(u"Interface"), wx.DefaultPosition, wx.DefaultSize, 0 )
self.staticTextConfigInterface.Wrap( -1 )

Expand All @@ -221,6 +224,9 @@ def __init__( self, parent ):
self.comboBoxConfigInterface.SetSelection( 0 )
fgSizer31.Add( self.comboBoxConfigInterface, 0, wx.ALL, 5 )


fgSizer31.Add( ( 0, 0), 1, wx.EXPAND, 5 )

self.staticTextConfigLanguage = wx.StaticText( self.panelConfig, wx.ID_ANY, _(u"Language"), wx.DefaultPosition, wx.DefaultSize, 0 )
self.staticTextConfigLanguage.Wrap( -1 )

Expand All @@ -231,6 +237,9 @@ def __init__( self, parent ):
self.comboBoxConfigLanguage.SetSelection( 0 )
fgSizer31.Add( self.comboBoxConfigLanguage, 0, wx.ALL, 5 )


fgSizer31.Add( ( 0, 0), 1, wx.EXPAND, 5 )

self.staticTextConfigCSVDelimiter = wx.StaticText( self.panelConfig, wx.ID_ANY, _(u"CSV delimiter"), wx.DefaultPosition, wx.DefaultSize, 0 )
self.staticTextConfigCSVDelimiter.Wrap( -1 )

Expand All @@ -242,14 +251,43 @@ def __init__( self, parent ):

fgSizer31.Add( self.textConfigCSVdelimiter, 0, wx.ALL, 5 )


fgSizer31.Add( ( 0, 0), 1, wx.EXPAND, 5 )

self.staticTextConfigLogfile = wx.StaticText( self.panelConfig, wx.ID_ANY, _(u"Logfile"), wx.DefaultPosition, wx.DefaultSize, 0 )
self.staticTextConfigLogfile.Wrap( -1 )

fgSizer31.Add( self.staticTextConfigLogfile, 0, wx.ALL, 5 )

self.textCtrlConfigLogfile = wx.TextCtrl( self.panelConfig, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
self.textCtrlConfigLogfile.SetMinSize( wx.Size( 400,-1 ) )

fgSizer31.Add( self.textCtrlConfigLogfile, 1, wx.ALL|wx.EXPAND, 5 )

self.buttonConfigLogfile = wx.Button( self.panelConfig, wx.ID_ANY, _(u"Logfile"), wx.DefaultPosition, wx.DefaultSize, 0 )
fgSizer31.Add( self.buttonConfigLogfile, 0, wx.ALL, 5 )

self.staticTextConfigLogLevel = wx.StaticText( self.panelConfig, wx.ID_ANY, _(u"Loglevel"), wx.DefaultPosition, wx.DefaultSize, 0 )
self.staticTextConfigLogLevel.Wrap( -1 )

fgSizer31.Add( self.staticTextConfigLogLevel, 0, wx.ALL, 5 )

comboBoxConfigLoglevelChoices = [ _(u"DEBUG"), _(u"ERROR") ]
self.comboBoxConfigLoglevel = wx.ComboBox( self.panelConfig, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, comboBoxConfigLoglevelChoices, 0 )
self.comboBoxConfigLoglevel.SetSelection( 1 )
fgSizer31.Add( self.comboBoxConfigLoglevel, 0, wx.ALL, 5 )


fgSizer31.Add( ( 0, 0), 1, wx.EXPAND, 5 )

self.buttonSaveConfig = wx.Button( self.panelConfig, wx.ID_ANY, _(u"Save"), wx.DefaultPosition, wx.DefaultSize, 0 )
fgSizer31.Add( self.buttonSaveConfig, 0, wx.ALL, 5 )


self.panelConfig.SetSizer( fgSizer31 )
self.panelConfig.Layout()
fgSizer31.Fit( self.panelConfig )
self.m_notebook3.AddPage( self.panelConfig, _(u"Configuration"), False )
self.m_notebook3.AddPage( self.panelConfig, _(u"Configuration"), True )

bSizer2.Add( self.m_notebook3, 1, wx.EXPAND |wx.ALL, 5 )

Expand Down Expand Up @@ -286,6 +324,7 @@ def __init__( self, parent ):
self.buttonClear.Bind( wx.EVT_BUTTON, self.clearFields )
self.buttonValidateSingle.Bind( wx.EVT_BUTTON, self.validateSingle )
self.buttonValidateBatch.Bind( wx.EVT_BUTTON, self.validateBatch )
self.buttonConfigLogfile.Bind( wx.EVT_BUTTON, self.openLogfile )
self.buttonSaveConfig.Bind( wx.EVT_BUTTON, self.saveConfig )
self.Bind( wx.EVT_MENU, self.vatvalidationClose, id = self.menuitemFileClose.GetId() )
self.Bind( wx.EVT_MENU, self.vatvalidationGitHub, id = self.menuitemHelpSupport.GetId() )
Expand All @@ -309,6 +348,9 @@ def validateSingle( self, event ):
def validateBatch( self, event ):
event.Skip()

def openLogfile( self, event ):
event.Skip()

def saveConfig( self, event ):
event.Skip()

Expand Down
3 changes: 2 additions & 1 deletion src/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
import json
import logging

logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s')

VERSION = "v2024-08-17"
VERSION = "v2024-11-06"
UPDATEURL = 'https://api.github.com/repos/dseichter/VATValidation/releases/latest'
RELEASES = 'https://github.com/dseichter/VATValidation/releases'
NAME = 'VAT-Validation'
Expand Down
39 changes: 39 additions & 0 deletions src/logging_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import logging
import settings


def setup_logging():

settings.create_config()
log_file = settings.load_value_from_json_file("logfilename")

# Create a logger
logger = logging.getLogger()
# get loglevel from environment
loglevel = settings.load_value_from_json_file("loglevel")
if loglevel == "DEBUG":
logger.setLevel(logging.DEBUG)
if loglevel == "INFO":
logger.setLevel(logging.INFO)
if loglevel == "ERROR":
logger.setLevel(logging.ERROR)

# Create a file handler
file_handler = logging.FileHandler(log_file)
if loglevel == "DEBUG":
file_handler.setLevel(logging.DEBUG)
if loglevel == "INFO":
file_handler.setLevel(logging.INFO)
if loglevel == "ERROR":
file_handler.setLevel(logging.ERROR)

# Create a formatter and set it for the handlers
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
file_handler.setFormatter(formatter)

# Add the handlers to the logger
logger.addHandler(file_handler)


# Call the setup_logging function to configure logging
setup_logging()
2 changes: 1 addition & 1 deletion src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
wxPython==4.2.2; sys_platform != "linux"
https://github.com/dseichter/wxpython-whl/releases/download/4.2.1/wxPython-4.2.1-cp312-cp312-linux_x86_64.whl; sys_platform == "linux"
https://github.com/dseichter/wxpython-whl/releases/download/4.2.2/wxPython-4.2.2-cp312-cp312-linux_x86_64.whl; sys_platform == "linux"
urllib3==2.2.3
pandas==2.2.3
numpy==2.1.3
Expand Down
14 changes: 14 additions & 0 deletions src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import json
import tempfile

CONFIGFILE = 'config.json'

Expand Down Expand Up @@ -41,6 +42,19 @@ def create_config():
with open(CONFIGFILE, 'r') as f:
data = json.load(f)

# check and add missing keys
if 'language' not in data:
data['language'] = 'en'
if 'interface' not in data:
data['interface'] = 'vies'
if 'delimiter' not in data:
data['delimiter'] = '|'
if 'logfilename' not in data:
log_dir = tempfile.gettempdir()
data['logfilename'] = f'{log_dir}/vatvalidation.log'
if 'loglevel' not in data:
data['loglevel'] = 'ERROR'

with open(CONFIGFILE, 'w') as f:
json.dump(data, f, indent=4, sort_keys=True)

Expand Down
5 changes: 5 additions & 0 deletions src/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

import validate_workflow

import logging_config # Setup the logging # noqa: F401
import logging

logger = logging.getLogger(__name__)


def validatesingle(
key1="",
Expand Down
24 changes: 8 additions & 16 deletions src/validate_bzst.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,18 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import datetime
import os
import urllib3
import defusedxml.minidom as minidom
import logging
import codes_bzst
import logging_config # Setup the logging # noqa: F401
import logging

logger = logging.getLogger(__name__)

logger = logging.getLogger()
http = urllib3.PoolManager()

URL = "https://evatr.bff-online.de/evatrRPC"

# get loglevel from environment
if "LOGLEVEL" in os.environ:
loglevel = os.environ["LOGLEVEL"]
if loglevel == "DEBUG":
logger.setLevel(logging.DEBUG)
if loglevel == "INFO":
logger.setLevel(logging.INFO)
if loglevel == "ERROR":
logger.setLevel(logging.ERROR)

validationresult = {
"key1": None,
"key2": None,
Expand Down Expand Up @@ -75,7 +66,10 @@ def load_codes(lang, errorcode):


def start_validation(payload):
logger.debug(payload)
logger.debug('-'*40)
logger.debug('BZST')
logger.debug('-'*40)
logger.debug("Starting validation with payload: %s", payload)

# map requested fields to bzst request
bzstmap = {
Expand All @@ -86,8 +80,6 @@ def start_validation(payload):
"PLZ": payload["zip"],
"Strasse": payload["street"],
}
# check, if there is valid history of the vat

try:
resp = http.request("GET", URL, fields=bzstmap)
rc = parse_response(resp.data)
Expand Down
23 changes: 9 additions & 14 deletions src/validate_hmrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,20 @@

import datetime
from decimal import Decimal
import os
import urllib3
import json
import logging

import codes_hmrc

logger = logging.getLogger()
import logging_config # noqa: F401
import logging

logger = logging.getLogger(__name__)

http = urllib3.PoolManager()

URL = "https://api.service.hmrc.gov.uk/organisations/vat/check-vat-number/lookup/"

# get loglevel from environment
if "LOGLEVEL" in os.environ:
loglevel = os.environ["LOGLEVEL"]
if loglevel == "DEBUG":
logger.setLevel(logging.DEBUG)
if loglevel == "INFO":
logger.setLevel(logging.INFO)
if loglevel == "ERROR":
logger.setLevel(logging.ERROR)

validationresult = {
"key1": None,
"key2": None,
Expand Down Expand Up @@ -85,7 +77,10 @@ def load_codes(lang, message):


def start_validation(payload):
logger.debug(payload)
logger.debug('-'*40)
logger.debug('HMRC')
logger.debug('-'*40)
logger.debug("Starting validation with payload: %s", payload)

try:
resp = http.request("GET", URL + payload["foreignvat"][2:])
Expand Down
Loading