"""orca-customizations.py, written by Storm Dragon Place this file in ~/.local/share/orca/ Released under the terms of the WTFPL license: http://wtfpl.net""" import orca.input_event # watches for input that Orca recognizes import orca.keybindings # Handles binding keystrokes for Orca to use. import orca.orca # Imports the main screen reader import orca.speech # Handles Orca's speaking abilities import orca.braille # Displays information in Braille format from xml.dom import minidom import subprocess import os import time import urllib #variable section #Postal code for weather information: zipCode = "28624" myKeyBindings = orca.keybindings.KeyBindings() #places text in the clipboard def setClipboardText(text): os.system("echo \"" + text + "\" | xclip -selection clipboard") #getWeather function gets weather from Yahoo def getWeather(zip_code, forecast = False): if zip_code != "0": WEATHER_URL = 'http://xml.weather.yahoo.com/forecastrss?p=%s' WEATHER_NS = 'http://xml.weather.yahoo.com/ns/rss/1.0' url = WEATHER_URL % zip_code dom = minidom.parse(urllib.urlopen(url)) forecasts = [] for node in dom.getElementsByTagNameNS(WEATHER_NS, 'forecast'): forecasts.append(node.getAttribute('text')) forecasts.append(node.getAttribute('high')) forecasts.append(node.getAttribute('low')) ycondition = dom.getElementsByTagNameNS(WEATHER_NS, 'condition')[0] weatherReport = "It is currently " + ycondition.getAttribute('temp') + " degrees and " + ycondition.getAttribute('text') + "." if forecast == True: weatherReport = "Today's forecast is " + str(forecasts[0]) + " with a high temperature of " + forecasts[1] + " and a low of " + forecasts[2] + " degrees." weatherReport = weatherReport.replace("AM", "morning") weatherReport = weatherReport.replace("PM", "evening") weatherReport = weatherReport.replace("Wind", "windy") weatherReport = weatherReport.replace("/", " and ") weatherReport = weatherReport.capitalize() else: weatherReport = "No zip code set: Please edit .orca/orca-customizations.py" setClipboardText(weatherReport) return weatherReport #define the battery status function def sayBattery(script, inputEvent=None): message = subprocess.check_output(["acpi"]) if len(message) == 0: message = "Battery not found." orca.speech.speak(message) orca.braille.displayMessage(message) return True #end battery status function #define the readClipboard function def readClipboard(script, inputEvent=None): #Get the clipboard cbText = subprecess.check_output(["xclip", "-o", "-selection clipboard"]) if len(cbText) == 0: cbText = "No text in clipboard." #Speak and braille the info orca.speech.speak(cbText) orca.braille.displayMessage(cbText) #end readClipboard function #Define the sayVersion function def sayVersion(script, inputEvent=None): message = "Orca version " + orca.orca_platform.version orca.speech.speak(message) orca.braille.displayMessage(message) setClipboardText(message) return True #end sayVersion function #Define the sayWeather function def sayWeather(script, inputEvent=None): message = getWeather(zipCode) orca.speech.speak(message) orca.braille.displayMessage(message) return True #end sayWeather function #Define the sayForecast function def sayForecast(script, inputEvent=None): message = getWeather(zipCode, True) orca.speech.speak(message) orca.braille.displayMessage(message) return True #end sayForecast function #Set up sayBattery keys sayBatteryHandler = orca.input_event.InputEventHandler( sayBattery, "Speaks and Brailles battery status.") # Shows the function of the key press in learn mode myKeyBindings.add(orca.keybindings.KeyBinding( "", 1 << orca.keybindings.MODIFIER_ORCA, 1 << orca.keybindings.MODIFIER_ORCA, sayBatteryHandler)) # Sets Orca-a as the battery status key #Set up readClipboard keys readClipboardHandler = orca.input_event.InputEventHandler( readClipboard, "Speaks and Brailles clipboard contents.") # Shows the function of the key press in learn mode myKeyBindings.add(orca.keybindings.KeyBinding( "", 1 << orca.keybindings.MODIFIER_ORCA, 1 << orca.keybindings.MODIFIER_ORCA, readClipboardHandler)) # Sets Orca-r as the read clipboard key #Set up sayVersion keys sayVersionHandler = orca.input_event.InputEventHandler( sayVersion, "Presents the version of Orca.") # Shows the function of the key press in learn mode myKeyBindings.add(orca.keybindings.KeyBinding( "", 1 << orca.keybindings.MODIFIER_ORCA, 1 << orca.keybindings.MODIFIER_ORCA, sayVersionHandler)) # Sets the say time key #add sayWeather info sayWeatherHandler = orca.input_event.InputEventHandler( sayWeather, "Get current temperature and conditions.") # Shows the function of the key press in learn mode myKeyBindings.add(orca.keybindings.KeyBinding( "", 1 << orca.keybindings.MODIFIER_ORCA, 1 << orca.keybindings.MODIFIER_ORCA, sayWeatherHandler)) # Sets the say weather key #add sayForecast info sayForecastHandler = orca.input_event.InputEventHandler( sayForecast, "Get extended weather information.") # Shows the function of the key press in learn mode myKeyBindings.add(orca.keybindings.KeyBinding( "", 1 << orca.keybindings.MODIFIER_ORCA, 1 << orca.keybindings.MODIFIER_ORCA, sayForecastHandler, 2)) # Sets the say weather key orca.settings.keyBindingsMap["default"] = myKeyBindings #end time, date, and weather code