Skip to content

Commit

Permalink
Fix owner downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
meyermarcel committed Oct 30, 2024
1 parent 88aa58f commit c79c80e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
39 changes: 25 additions & 14 deletions http/owners_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func parseOwners(body io.Reader) ([]cont.Owner, error) {
tbody := tableBody(n)

if tbody != nil {
Rows:
for child1 := tbody.FirstChild; child1 != nil; child1 = child1.NextSibling {
tr := tableRow(child1)
if tr != nil {
Expand All @@ -65,21 +66,31 @@ func parseOwners(body io.Reader) ([]cont.Owner, error) {
for child2 := tr.FirstChild; child2 != nil; child2 = child2.NextSibling {
td := tableData(child2)
if td != nil {
if td.FirstChild != nil {
d := td.FirstChild.Data
switch tdIdx {
case 0:
if len(d) < 4 {
return fmt.Errorf("parsing HTML failed of owner code failed because '%s' is too short", d)
}
owner.Code = d[0:3]
case 1:
owner.Company = d
case 3:
owner.City = d
case 5:
owner.Country = cmp.Or(countryCodeMap[d], d)

if td.FirstChild == nil {
// First td is an empty string. Skip this row.
if tdIdx == 0 {
continue Rows
}
// Next td
tdIdx++
continue
}

d := td.FirstChild.Data

switch tdIdx {
case 0:
if len(d) != 4 {
continue Rows
}
owner.Code = d[0:3]
case 1:
owner.Company = d
case 3:
owner.City = d
case 5:
owner.Country = cmp.Or(countryCodeMap[d], d)
}
tdIdx++
}
Expand Down
13 changes: 13 additions & 0 deletions http/owners_downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ func validBody() io.Reader {
</tr>
</thead>
<tbody>
<tr class="nostripe">
<td class="flexMobile align-items-center dtr-control sorting_1" tabindex="0"></span></td>
<td class="flexMobile align-items-center">VANTAGE FORWARDING &amp; SHIPPING HK LIMITED</td>
<td class="flexMobile align-items-center">33B United Centre, 95 Queensway, Admiralty</td>
<td class="flexMobile align-items-center"></td>
<td class="flexMobile align-items-center">200072</td>
<td class="flexMobile align-items-center">HK</td>
<td data-geofence="0" class="no-sort flexMobile detailWidth">
<div class="d-flex my-1 my-md-0 position-relative d-flex justify-content-start justify-content-md-end align-items-center">
<a class="upperCase withArrow" href="/bic-codes//">View</a>
</div>
</td>
</tr>
<tr class="nostripe">
<td class="flexMobile align-items-center">AAAU</span></td>
<td class="flexMobile align-items-center">A Company</span></td>
Expand Down

0 comments on commit c79c80e

Please # to comment.