<commit_before>#!/usr/bin/env python
#
# Script to update dynamic DNS records at DNSMadeEasy.com with HTTPS support.
# Put your settings in settings.json in the same folder with the script 
# and set to run from cron.
#
# Requires following non-core modules;
#  * python-requests, https://pypi.python.org/pypi/requests/
#  * python-dns, https://pypi.python.org/pypi/dnspython/
#
# Original Author: <NAME> <<EMAIL>>
#
# Author: Painful Cranium Consulting, LLC ( <NAME><<EMAIL>> )
# Date Modified:
# 06/03/2015
#
# Notes:
# Forked from original author and updated to allow multi record JSON to be used
# so many records could be updated at once.
#
# If you find this useful, please drop me a line and let
# me know how this has helped you :)
#
# License: MIT, https://github.com/painfulcranium/dnsmadeeasy_api_updater/blob/master/LICENSE

from __future__ import print_function

import socket
import json
import logging
import os
import sys
import argparse
import requests
import dns.resolver

logging.basicConfig(format='%(levelname)s: %(message)s')
logger = logging.getLogger(__name__)


def error(message):
    """
    Log an error and exit.
    """
    logger.error(message)
    sys.exit(1)


def check_ssl(url):
    try:
        requests.get(url, verify=True)
    except requests.exceptions.SSLError:
        error('The SSL certificate for %s is not valid.' % (url))


def get_current_ip(url):
    url = url
    try:
        return requests.get(url).text.strip()
    except requests.ConnectionError:
        logger.debug('Could not get the current IP from %s' % (url))


def get_dns_ip(name, target='A'):
    name = name
    bits = name.split('.')
    while bits:
        try:
            ns = str(dns.resolver.query('.'.join(bits), 'NS')[0])
        except:
            bits.pop(0)
        else:
            ns = socket.gethostbyname(ns)
            resolver = dns.resolver.Resolver()
            resolver.nameservers = [ns]
            q = resolver.query(name, target)
            ip = str(q[0]).strip()
            return ip
    error('Could not get the authoritative name server for %s.' % (name))


def update_ip_to_dns(ip, url, username, record_id, record_password):
    url = url
    check_ssl(url)
    params = {
        'username': username,
        'password': <PASSWORD>,
        'id': record_id,
        'ip': ip,
    }
    return requests.get(url, params=params)

# Constants
BASE_DIR = os.path.dirname(__file__)
GET_IP_URL = 'http://www.dnsmadeeasy.com/myip.jsp'
UPDATE_IP_URL = 'https://www.dnsmadeeasy.com/servlet/updateip'
LOG_LEVEL = 'DEBUG'

try:
    logger.setLevel(LOG_LEVEL)
except ValueError:
    logger.error('Invalid `LOG_LEVEL`. Valid levels are: DEBUG, INFO, WARNING, ERROR, CRITICAL.')
    sys.exit(1)

if __name__ == '__main__':

        parser = argparse.ArgumentParser()
        parser.add_argument('--jsonConfig', type=str)
        parser.add_argument('--jsonKey', type=str)<commit_msg>Added some help text to argument parser<commit_after>#!/usr/bin/env python
#
# Script to update dynamic DNS records at DNSMadeEasy.com with HTTPS support.
# Put your settings in settings.json in the same folder with the script 
# and set to run from cron.
#
# Requires following non-core modules;
#  * python-requests, https://pypi.python.org/pypi/requests/
#  * python-dns, https://pypi.python.org/pypi/dnspython/
#
# Original Author: <NAME> <<EMAIL>>
#
# Author: Painful Cranium Consulting, LLC ( <NAME><<EMAIL>> )
# Date Modified:
# 06/03/2015
#
# Notes:
# Forked from original author and updated to allow multi record JSON to be used
# so many records could be updated at once.
#
# If you find this useful, please drop me a line and let
# me know how this has helped you :)
#
# License: MIT, https://github.com/painfulcranium/dnsmadeeasy_api_updater/blob/master/LICENSE

from __future__ import print_function

import socket
import json
import logging
import os
import sys
import argparse
import requests
import dns.resolver

logging.basicConfig(format='%(levelname)s: %(message)s')
logger = logging.getLogger(__name__)


def error(message):
    """
    Log an error and exit.
    """
    logger.error(message)
    sys.exit(1)


def check_ssl(url):
    try:
        requests.get(url, verify=True)
    except requests.exceptions.SSLError:
        error('The SSL certificate for %s is not valid.' % (url))


def get_current_ip(url):
    url = url
    try:
        return requests.get(url).text.strip()
    except requests.ConnectionError:
        logger.debug('Could not get the current IP from %s' % (url))


def get_dns_ip(name, target='A'):
    name = name
    bits = name.split('.')
    while bits:
        try:
            ns = str(dns.resolver.query('.'.join(bits), 'NS')[0])
        except:
            bits.pop(0)
        else:
            ns = socket.gethostbyname(ns)
            resolver = dns.resolver.Resolver()
            resolver.nameservers = [ns]
            q = resolver.query(name, target)
            ip = str(q[0]).strip()
            return ip
    error('Could not get the authoritative name server for %s.' % (name))


def update_ip_to_dns(ip, url, username, record_id, record_password):
    url = url
    check_ssl(url)
    params = {
        'username': username,
        'password': <PASSWORD>,
        'id': record_id,
        'ip': ip,
    }
    return requests.get(url, params=params)

# Constants
BASE_DIR = os.path.dirname(__file__)
GET_IP_URL = 'http://www.dnsmadeeasy.com/myip.jsp'
UPDATE_IP_URL = 'https://www.dnsmadeeasy.com/servlet/updateip'
LOG_LEVEL = 'DEBUG'

try:
    logger.setLevel(LOG_LEVEL)
except ValueError:
    logger.error('Invalid `LOG_LEVEL`. Valid levels are: DEBUG, INFO, WARNING, ERROR, CRITICAL.')
    sys.exit(1)

if __name__ == '__main__':

        parser = argparse.ArgumentParser()
        parser.add_argument('--jsonConfig', type=str, help='Configuration file in current directory')
        parser.add_argument('--jsonKey', type=str, help='JSON Dict Key to use')
{'fraction_non_alphanumeric': 0.12317011610297829, 'fraction_numerical': 0.004374894834258792, 'mean_word_length': 3.096485182632667, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 8, 'lorem ipsum': 0, 'www.': 4, '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': '4008087', 'n_tokens_mistral': 1960, 'n_tokens_neox': 1906, 'n_words': 529}