import sys

if len(sys.argv) != 2:
  print('Usage:\npython3 <TLD list>')
  sys.exit()

tld = []
all_tld = []
not_tld = []

for line in open(sys.argv[1]):
  i = line.find('//')
  if i >= 0:
    line = line[:i]
  line = line.strip()
  if '.' not in line:
    continue

  if line.startswith('!'):
    not_tld.append(line[1:])
  elif line.startswith('*.'):
    all_tld.append(line[2:])
  else:
    tld.append(line)

print("""// Generated by convert_tld.py. Don\'t edit manually.

var EFFECTIVE_TLD = [
  '{}'
];

var CHILDREN_TLD = [
  '{}'
];

var NOT_TLD = [
  '{}'
];
""".format('\',\n  \''.join(tld),
           '\',\n  \''.join(all_tld),
           '\',\n  \''.join(not_tld)))

import sys

if len(sys.argv) != 2:
  print('Usage:\npython3 <TLD list>')
  sys.exit()

tld = []
all_tld = []
not_tld = []

for line in open(sys.argv[1]):
  i = line.find('//')
  if i >= 0:
    line = line[:i]
  line = line.strip()
  if '.' not in line:
    continue

  if line.startswith('!'):
    not_tld.append(line[1:])
  elif line.startswith('*.'):
    all_tld.append(line[2:])
  else:
    tld.append(line)

print("""// Generated by convert_tld.py. Don\'t edit manually.

var EFFECTIVE_TLD = [
  '{}'
];

var CHILDREN_TLD = [
  '{}'
];

var NOT_TLD = [
  '{}'
];
""".format('\',\n  \''.join(tld),
           '\',\n  \''.join(all_tld),
           '\',\n  \''.join(not_tld)))

// Generated by convert_tld.py. Don\'t edit manually.  var EFFECTIVE_TLD = [   '{}' ];  var CHILDREN_TLD = [   '{}' ];  var NOT_TLD = [   '{}' ];