Skip to content

Instantly share code, notes, and snippets.

@mjuenema
Created April 11, 2018 01:32
Show Gist options
  • Save mjuenema/e0faf550e8d92d5cd9231683689c216b to your computer and use it in GitHub Desktop.
Save mjuenema/e0faf550e8d92d5cd9231683689c216b to your computer and use it in GitHub Desktop.
Convert IANA Enterprise Numbers to JSON
#!/usr/bin/env python
# Convert IANA Enterprise Numbers to JSON
#
# TODO: Deal with "misformatted" lines in input better.
#
# (c) 2018 Markus Juenemann <markus&juenemann.net>
import json
import urllib
data = {}
fp = urllib.urlopen('https://www.iana.org/assignments/enterprise-numbers/enterprise-numbers')
number = None
organization = None
contact = None
email = None
for line in fp:
if line.startswith(' '):
email = line.strip()
if number is not None and organization is not None and contact is not None and email is not None :
try:
data[int(number)] = {'organization': organization, 'contact': contact, 'email': email}
except Exception as e:
print(e, number, organization, contact, email)
else:
print('Data missing', number, organization, contact, email)
number = None
organization = None
contact = None
email = None
elif line.startswith(' '):
contact = line.strip()
elif line.startswith(' '):
organization = line.strip()
else:
number = line.strip()
with open('enterprise-numbers.json', 'wb') as fp:
json.dump(data, fp, indent=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment