示例#1
0
class TwilioVocalizer(object):
    def __init__(self):
        self.wrapper = TwilioWrapper()
        self.vocalizer = Vocalizer()

    def vocalize(self, action_type, number, message=None):
        statement = "I am now %s number %s" % (action_type, number)
        if action_type == "messaging":
            self.wrapper.message_home(message)
            statement += " with message %s" % message
        elif action_type == "calling":
            self.wrapper.call_home()
        self.vocalizer.vocalize(statement)
class BloombergVocalizer(object):
    def __init__(self):
        self.wrapper = BloombergWrapper()
        self.vocalizer = Vocalizer()

    def vocalize(self, securities):
        prices = self.wrapper.request(securities)

        statement = ""
        i = 0
        for security in securities:
            statement += "The current price of %s is %s dollars. " % (security, prices[i])
            i += 1

        self.vocalizer.vocalize(statement)
示例#3
0
class TeslaVocalizer(object):
	def __init__(self, is_local=True):
		self.vocalizer = Vocalizer()
		self.wrapper = TeslaWrapper(is_local)

	def response_success_checker(self, response):
		if response:
			if "result" in response:
				if response["result"] == True:
					return True
		return False

	def get_mobile_enabled(self):
		r = self.wrapper.get_mobile_enabled()
		if self.response_success_checker(r):
			self.vocalizer.vocalize("Mobile access is enabled.")
		else:
			self.vocalizer.vocalize("Mobile access is not enabled.")

	def open_charge_port_door(self):
		r = self.wrapper.open_charge_port_door()
		if self.response_success_checker(r):
			self.vocalizer.vocalize("Opening charge port door.")
		else:
			self.vocalizer.vocalize("Unable to open charge port door.")

	def start_charge(self):
		r = self.wrapper.start_charge()
		if self.response_success_checker(r):
			self.vocalizer.vocalize("Starting to charge the vehicle.")
		else:
			self.vocalizer.vocalize("Unable to charge the vehicle.")

	def stop_charge(self):
		r = self.wrapper.stop_charge()
		if self.response_success_checker(r):
			self.vocalizer.vocalize("Stopping charging of vehicle.")
		else:
			self.vocalizer.vocalize("Unable to stop charging the vehicle.")

	def flash_lights(self):
		r = self.wrapper.flash_lights()
		if self.response_success_checker(r):
			self.vocalizer.vocalize("Flashing the lights once.")
		else:
			self.vocalizer.vocalize("Unable to flash the lights.")

	def honk_horn(self):
		r = self.wrapper.honk_horn()
		if self.response_success_checker(r):
			self.vocalizer.vocalize("Honking the horn.")
		else:
			self.vocalizer.vocalize("Unable to honk the horn.")

	def unlock_door(self):
		r = self.wrapper.unlock_door()
		if self.response_success_checker(r):
			self.vocalizer.vocalize("Unlocking the doors.")
		else:
			self.vocalizer.vocalize("Unable to unlock the doors.")

	def lock_door(self):
		r = self.wrapper.lock_door()
		if self.response_success_checker(r):
			self.vocalizer.vocalize("Locking the doors.")
		else:
			self.vocalizer.vocalize("Unable to lock the doors.")

	def open_sun_roof(self):
		r = self.wrapper.open_sun_roof()
		if self.response_success_checker(r):
			self.vocalizer.vocalize("Opening the sun roof.")
		else:
			self.vocalizer.vocalize("Unable to open the sun roof.")

	def close_sun_roof(self):
		r = self.wrapper.close_sun_roof()
		if self.response_success_checker(r):
			self.vocalizer.vocalize("Closing the sun roof.")
		else:
			self.vocalizer.vocalize("Unable to close the sun roof.")