diff options
author | Gustavo Valverde <gustavo@iterativo.do> | 2020-02-18 19:18:39 +0100 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2020-02-18 21:07:20 +0100 |
commit | efa70f1ece9f30bf7e6a8600534bbb37e751c53e (patch) | |
tree | 4c7fda443b0e1a872e62cdefd7415a9567b5da47 /stdnum/do/ncf.py | |
parent | e513888762af9c0d5fd698810e124cb9b5a47a92 (diff) |
Change DGII endpoint to new one
The old endpoint has been deprecated.
Closes https://github.com/arthurdejong/python-stdnum/pull/190
Diffstat (limited to 'stdnum/do/ncf.py')
-rw-r--r-- | stdnum/do/ncf.py | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/stdnum/do/ncf.py b/stdnum/do/ncf.py index b9bb3d9..d4994de 100644 --- a/stdnum/do/ncf.py +++ b/stdnum/do/ncf.py @@ -133,10 +133,13 @@ def _convert_result(result): # pragma: no cover 'MENSAJE_VALIDACION': 'validation_message', 'RNC': 'rnc', 'NCF': 'ncf', + u'RNC / Cédula': 'rnc', u'RNC/Cédula': 'rnc', + u'Nombre / Razón Social': 'name', u'Nombre/Razón Social': 'name', 'Estado': 'status', 'Tipo de comprobante': 'type', + u'Válido hasta': 'valid_until', } return dict( (translation.get(key, key), value) @@ -168,13 +171,14 @@ def check_dgii(rnc, ncf, timeout=30): # pragma: no cover from stdnum.do.rnc import compact as rnc_compact rnc = rnc_compact(rnc) ncf = compact(ncf) - url = 'https://www.dgii.gov.do/app/WebApps/ConsultasWeb/consultas/ncf.aspx' - headers = { + url = 'https://dgii.gov.do/app/WebApps/ConsultasWeb2/ConsultasWeb/consultas/ncf.aspx' + session = requests.Session() + session.headers.update({ 'User-Agent': 'Mozilla/5.0 (python-stdnum)', - } + }) # Get the page to pick up needed form parameters document = lxml.html.fromstring( - requests.get(url, headers=headers, timeout=timeout).text) + session.get(url, timeout=timeout).text) validation = document.find('.//input[@name="__EVENTVALIDATION"]').get('value') viewstate = document.find('.//input[@name="__VIEWSTATE"]').get('value') data = { @@ -186,13 +190,13 @@ def check_dgii(rnc, ncf, timeout=30): # pragma: no cover } # Do the actual request document = lxml.html.fromstring( - requests.post(url, headers=headers, data=data, timeout=timeout).text) - result = document.find('.//div[@id="ctl00_cphMain_pResultado"]') + session.post(url, data=data, timeout=timeout).text) + result = document.find('.//div[@id="cphMain_pResultado"]') if result is not None: data = { - 'validation_message': document.findtext('.//*[@id="ctl00_cphMain_lblInformacion"]').strip(), + 'validation_message': document.findtext('.//*[@id="cphMain_lblInformacion"]').strip(), } data.update(zip( - [x.text.strip().rstrip(':') for x in result.findall('.//strong')], - [x.text.strip() for x in result.findall('.//span')])) + [x.text.strip() for x in result.findall('.//th')], + [x.text.strip() for x in result.findall('.//td/span')])) return _convert_result(data) |