Skip to content

filter.py - trim does not cut as expected #1

@johnhtodd

Description

@johnhtodd

I'd like to use standard JSON formatting to specify what fields or arrays should be trimmed.

I had an arguments file that looks like this:

(.venv) root@mmdbpython:/home/jtodd/GeoIP2-Enterprise_20241018# cat arguments
continent
country.confidence
country.geoname_id
location.time_zone
postal
registered_country.geoname_id
traits.autonomous_system_number
traits.autonomous_system_organization
traits.isp
traits.organization
traits.domain
subdivisions.geoname_id

and applied it to an MMDB file that had objects in it that should have matched those namespaces.

../mrt2mmdb/mrt2mmdb/filter.py --trim `cat arguments` --mmdb GeoIP2-Enterprise.mmdb.trim1

This leads to objects that still contain fields I expected to be trimmed:

{
  "city": {
    "confidence": 20,
    "geoname_id": 6698658,
    "names": {
      "en": "Ko Pha Ngan"
    }
  },
  "country": {
    "confidence": 59,
    "geoname_id": 1635651,
    "iso_code": "TH",
    "names": {
      "en": "Thailand"
    }
  },
  "location": {
    "accuracy_radius": 100,
    "latitude": 9.4167,
    "longitude": 101,
    "time_zone": "Asia/Bangkok"
  },
  "range": "1.0.163.56/29",
  "registered_country": {
    "geoname_id": 1675651,
    "iso_code": "TH",
    "names": {
      "en": "Thailand"
    }
  },
  "subdivisions": [
    {
      "confidence":90,
      "geoname_id": 1130524,
      "iso_code": "84",
      "names": {
        "en": "Surat Thani"
      }
    }
  ],
  "traits": {
    "autonomous_system_number": 22969,
    "autonomous_system_organization": "TOT Public Company Limited",
    "connection_type": "Cable/DSL",
    "domain": "totinternet.net",
    "isp": "TOT",
    "organization": "TOT",
    "user_type": "residential"
  }
}

The "continent" and "postal" and other top-level objects were deleted, but the second-level items were not.

If an array or object matches the name given, then it should be deleted.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions