<commit_before>import json
import requests

misperrors = {'error': 'Error'}
mispattributes = {'input': ['hostname', 'domain']}

# possible module-types: 'expansion', 'hover' or both
moduleinfo = {'version': '1', 'author': '<NAME>',
              'description': 'Expand Country Codes',
              'module-type': ['hover']}

# config fields that your code expects from the site admin
moduleconfig = []

common_tlds = {"com":"Commercial (Worldwide)",
               "org":"Organisation (Worldwide)",
               "net":"Network (Worldwide)",
               "int":"International (Worldwide)",
               "edu":"Education (Usually USA)",
               "gov":"Government (USA)"
              }

def handler(q=False):
    if q is False:
        return False
    request = json.loads(q)
    domain = request["domain"]

    # Get the extension
    ext = domain.split(".")[-1]

    # Check if if's a common, non country one 
    if ext in common_tlds.keys():
      val = common_tlds[ext]
    else:
      # Retrieve a json full of country info
      codes = requests.get("http://www.geognos.com/api/en/countries/info/all.json").json()

      if not codes["StatusMsg"] == "OK":
        val = "Unknown"
      else:
        # Find our code based on TLD<commit_msg>CountryCode JSON now is only grabbed once per server run<commit_after>import json
import requests

misperrors = {'error': 'Error'}
mispattributes = {'input': ['hostname', 'domain']}

# possible module-types: 'expansion', 'hover' or both
moduleinfo = {'version': '1', 'author': '<NAME>',
              'description': 'Expand Country Codes',
              'module-type': ['hover']}

# config fields that your code expects from the site admin
moduleconfig = []

common_tlds = {"com":"Commercial (Worldwide)",
               "org":"Organisation (Worldwide)",
               "net":"Network (Worldwide)",
               "int":"International (Worldwide)",
               "edu":"Education (Usually USA)",
               "gov":"Government (USA)"
              }

codes = requests.get("http://www.geognos.com/api/en/countries/info/all.json").json()

def handler(q=False):
    global codes
    if q is False:
        return False
    request = json.loads(q)
    domain = request["domain"]

    # Get the extension
    ext = domain.split(".")[-1]

    # Check if if's a common, non country one 
    if ext in common_tlds.keys():
      val = common_tlds[ext]
    else:
      # Retrieve a json full of country info
      if not codes["StatusMsg"] == "OK":
        val = "Unknown"
      else:
        # Find our code based on TLD
{'fraction_non_alphanumeric': 0.14607614607614608, 'fraction_numerical': 0.001554001554001554, 'mean_word_length': 2.5566298342541436, 'pattern_counts': {'":': 14, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3424937', 'n_tokens_mistral': 760, 'n_tokens_neox': 744, 'n_words': 224}