Skip to content

Commit

Permalink
Update German OffeneRegister lookup data format
Browse files Browse the repository at this point in the history
It appears that the data structure at OffeneRegister has changed which
requires a different query. Data is returned in a different structure.
  • Loading branch information
arthurdejong committed Nov 13, 2022
1 parent 5cdef0d commit f691bf7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
47 changes: 19 additions & 28 deletions stdnum/de/handelsregisternummer.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,17 @@ def check_offeneregister(number, timeout=30): # pragma: no cover (not part of n
It will contain something like the following::
{
'retrieved_at': '2018-06-24T12:34:53Z',
'native_company_number': 'The number requested',
'company_number': 'Compact company number',
'registrar': 'Registar',
'federal_state': 'State name',
'registered_office': 'Office',
'register_art': 'Register type',
'register_nummer': 'Number'
'name': 'The name of the organisation',
'current_status': 'currently registered',
'companyId': 'U1206_HRB14011',
'courtCode': 'U1206',
'courtName': 'Chemnitz',
'globalId': 'sn_293298',
'isCurrent': 'True',
'name': 'Internet hier GmbH Presentation Provider',
'nativeReferenceNumber': 'Chemnitz HRB 14011',
'referenceNumberFirstSeen': '2020-06-12',
'stdRefNo': 'U1206_HRB14011',
'validFrom': '2020-06-12',
'validTill': '',
}
Will return None if the number is invalid or unknown.
Expand All @@ -350,27 +351,17 @@ def check_offeneregister(number, timeout=30): # pragma: no cover (not part of n
# network access for the tests and unnecessarily load the web service
import requests
court, registry, number, qualifier = _split(number)
# First lookup the registrar code
# (we could look up the number by registrar (court), registry and number
# but it seems those queries are too slow)
response = requests.get(
_offeneregister_url,
params={
'sql': 'select company_number from company where registrar = :p0 limit 1',
'p0': court},
timeout=timeout)
response.raise_for_status()
try:
registrar = response.json()['rows'][0][0].split('_')[0]
except (KeyError, IndexError) as e: # noqa: F841
raise InvalidComponent() # unknown registrar code
# Lookup the number
number = '%s_%s%s' % (registrar, registry, number)
response = requests.get(
_offeneregister_url,
params={
'sql': 'select * from company where company_number = :p0 limit 1',
'p0': number},
'sql': '''
select *
from ReferenceNumbers
join Names on ReferenceNumbers.companyId = Names.companyId
where nativeReferenceNumber = :p0
limit 1
''',
'p0': '%s %s %s' % (court, registry, number)},
timeout=timeout)
response.raise_for_status()
try:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_de_handelsregisternummer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_check_offeneregister(self):
result = handelsregisternummer.check_offeneregister('Chemnitz HRB 14011')
self.assertTrue(all(
key in result.keys()
for key in ['company_number', 'current_status', 'federal_state', 'registrar', 'native_company_number']))
for key in ['companyId', 'courtCode', 'courtName', 'name', 'nativeReferenceNumber']))
# Test invalid number
result = handelsregisternummer.check_offeneregister('Chemnitz HRA 14012')
self.assertIsNone(result)

0 comments on commit f691bf7

Please sign in to comment.