<commit_before>import json
import geoip2.database
import sys
import logging

log = logging.getLogger('geoip_asn')
log.setLevel(logging.DEBUG)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
log.addHandler(ch)

misperrors = {'error': 'Error'}
mispattributes = {'input': ['ip-src', 'ip-dst', 'domain|ip'], 'output': ['freetext']}
moduleconfig = ['local_geolite_db']
# possible module-types: 'expansion', 'hover' or both
moduleinfo = {'version': '0.1', 'author': 'GlennHD',
              'description': 'Query a local copy of the Maxmind Geolite ASN database (MMDB format)',
              'module-type': ['expansion', 'hover']}

def handler(q=False):
    if q is False:
        return False
    request = json.loads(q)

    if not request.get('config') or not request['config'].get('local_geolite_db'):
        return {'error': 'Please specify the path of your local copy of the Maxmind Geolite ASN database'}
    path_to_geolite = request['config']['local_geolite_db']

    if request.get('ip-dst'):
        toquery = request['ip-dst']
    elif request.get('ip-src'):<commit_msg>Update geoip_asn.py<commit_after>import json
import geoip2.database
import sys
import logging

log = logging.getLogger('geoip_asn')
log.setLevel(logging.DEBUG)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
log.addHandler(ch)

misperrors = {'error': 'Error'}
mispattributes = {'input': ['ip-src', 'ip-dst', 'domain|ip'], 'output': ['freetext']}
moduleconfig = ['local_geolite_db']
# possible module-types: 'expansion', 'hover' or both
moduleinfo = {'version': '0.1', 'author': 'GlennHD',
              'description': 'Query a local copy of the Maxmind Geolite ASN database (MMDB format)',
              'module-type': ['expansion', 'hover']}


def handler(q=False):
    if q is False:
        return False
    request = json.loads(q)

    if not request.get('config') or not request['config'].get('local_geolite_db'):
        return {'error': 'Please specify the path of your local copy of the Maxmind Geolite ASN database'}
    path_to_geolite = request['config']['local_geolite_db']

    if request.get('ip-dst'):
        toquery = request['ip-dst']
    elif request.get('ip-src'):
{'fraction_non_alphanumeric': 0.15971935617003716, 'fraction_numerical': 0.0024762690879075525, 'mean_word_length': 4.434977578475336, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1204444', 'n_tokens_mistral': 804, 'n_tokens_neox': 781, 'n_words': 200}