<commit_before># Python API Wrapper for cloudatcost.com

LIST_SERVERS_URL = "https://panel.cloudatcost.com/api/v1/listservers.php"
LIST_TEMPLATES_URL = "https://panel.cloudatcost.com/api/v1/listtemplates.php"
LIST_TASKS_URL = "https://panel.cloudatcost.com/api/v1/listtasks.php"
POWER_OPERATIONS_URL = "https://panel.cloudatcost.com/api/v1/powerop.php"
CONSOLE_URL = "https://panel.cloudatcost.com/api/v1/console.php"

import requests

class CACPy:
	"""Base class for making requests to the cloud at cost API."""

	def __init__(self,email,api_key):
		self.email = email
		self.api_key = api_key

	def _make_request(self,url,options=dict(),type="GET"):
		data = {
			'key':		self.api_key,
			'login':	self.email
		}

		for key in options:
			data[key] = options[key]

		print "URL: " + str(url)
		print "Data: " 
		print data

		ret = None
		if type == "GET":
			ret = requests.get(url,params=data)
		elif type == "POST":
			ret = requests.post(url,data=data)
		else:
			raise Exception("InvalidRequestType: " + str(type))

		return ret.json()

	def _commit_power_operation(self,server_id,operation):
		options = {'sid': server_id,'action':operation}
		return self._make_request(POWER_OPERATIONS_URL,options=options,type="POST")

	def get_server_info(self):
		jdata = self._make_request(LIST_SERVERS_URL)
		return jdata['data']

	def get_template_info(self):
		jdata = self._make_request(LIST_TEMPLATES_URL)
		return jdata['data']

	def get_task_info(self):
		jdata = self._make_request(LIST_TASKS_URL)
		return jdata['data']

	def power_on_server(self,server_id):
		return self._commit_power_operation(server_id,'poweron')

	def power_off_server(self,server_id):
		return self._commit_power_operation(server_id,'poweroff')

	def reset_server(self,server_id):
		return self._commit_power_operation(server_id,'reset')

	def get_console_url(self,server_id):
		options = {'sid': server_id}
		ret_data = self._make_request(CONSOLE_URL,options=options,type="POST")
		return ret_data['console']<commit_msg>Removed debug output from _make_request(). Added docstrings to all public methods and made cosmetic modifications to meet PEP-8 coding standards.<commit_after># Python API Wrapper for cloudatcost.com

import requests

LIST_SERVERS_URL = "https://panel.cloudatcost.com/api/v1/listservers.php"
LIST_TEMPLATES_URL = "https://panel.cloudatcost.com/api/v1/listtemplates.php"
LIST_TASKS_URL = "https://panel.cloudatcost.com/api/v1/listtasks.php"
POWER_OPERATIONS_URL = "https://panel.cloudatcost.com/api/v1/powerop.php"
CONSOLE_URL = "https://panel.cloudatcost.com/api/v1/console.php"


class CACPy:
    """Base class for making requests to the cloud at cost API."""

    def __init__(self, mail, api_key):
        """Return a CACPy object.

        Required Arguments:
        email - The email address used to authenticate to the API.
        api_key - The key generated in the CAC panel to access the API.
        """
        self.email = email
        self.api_key = api_key

    def _make_request(self, url, options=dict(), type="GET"):
        data = {
            'key': self.api_key,
            'login': self.email
        }

        # Add any passed in options to the data dictionary to be included
        # in the web request.
        for key in options:
            data[key] = options[key]

        ret = None
        if type == "GET":
            ret = requests.get(url, params=data)
        elif type == "POST":
            ret = requests.post(url, data=data)
        else:
            raise Exception("InvalidRequestType: " + str(type))

        return ret.json()

    def _commit_power_operation(self, server_id, operation):
        options = {
            'sid': server_id,
            'action': operation
        }
        return self._make_request(POWER_OPERATIONS_URL,
                                  options=options,
                                  type="POST")

    def get_server_info(self):
        """Return an array of dictionaries containing server details.

        The dictionaries will contain keys consistent with the 'data'
        portion of the JSON as documented here:
        https://github.com/cloudatcost/api#list-servers
        """
        jdata = self._make_request(LIST_SERVERS_URL)
        return jdata['data']

    def get_template_info(self):
        """Return an array of dictionaries containing template information.

        The dictionaries will contain keys consistent with the 'data'
        portion of the JSON as documented here:
        https://github.com/cloudatcost/api#list-templates
        """
        jdata = self._make_request(LIST_TEMPLATES_URL)
        return jdata['data']

    def get_task_info(self):
        """Return an array of dictionaries containing task information.

        The dictionaries will contain keys consistent with the 'data'
        portion of the JSON as documented here:
        https://github.com/cloudatcost/api#list-tasks
        """
        jdata = self._make_request(LIST_TASKS_URL)
        return jdata['data']

    def power_on_server(self, server_id):
        """Request that the server specified be powered on.

        Required Arguments:
        server_id - The unique ID assaciated with the server to power on.
                    Specified by the 'sid' key returned by get_server_info()

        The return value will be a dictionary that will contain keys consistent
        with the JSON as documented here:
        https://github.com/cloudatcost/api#power-operations
        """
        return self._commit_power_operation(server_id, 'poweron')

    def power_off_server(self, server_id):
        """Request that the server specified be powered off.

        Required Arguments:
        server_id - The unique ID associated with the server to power off.
                    Specified by the 'sid' key returned by get_server_info()

        The return value will be a dictionary that will contain keys consistent
        with the JSON as documented here:
        https://github.com/cloudatcost/api#power-operations
        """
        return self._commit_power_operation(server_id, 'poweroff')

    def reset_server(self, server_id):
        """Request that the server specified be power cycled.

        Required Arguments:
        server_id - The unique ID associated with the server to power off.
                    Specified by the 'sid' key returned by the get_server_info

        The return value will be a dictionary that will contain keys consistent
        with the JSON as documented here:
        https://github.com/cloudatcost/api#power-operations
        """
        return self._commit_power_operation(server_id, 'reset')

    def get_console_url(self, server_id):
        """Return the URL to the web console for the server specified.

        Required Arguments:
        server_id - The unique ID associated with the server you would
                    like the console URL for.
        """
        options = {
            'sid': server_id
        }
        ret_data = self._make_request(CONSOLE_URL,
                                      options=options,
                                      type="POST")
        return ret_data['console']
{'fraction_non_alphanumeric': 0.0944002234324815, 'fraction_numerical': 0.0015360983102918587, 'mean_word_length': 2.765509989484753, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 16, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5050838', 'n_tokens_mistral': 2152, 'n_tokens_neox': 2052, 'n_words': 567}