def main(): init_somebar() while True: ip = get_ip() if external_ip == ip: AnyBar(port=any_bar_port).change('green') else: AnyBar(port=any_bar_port).change('exclamation') time.sleep(delay)
def __init__(self, anybar_port=None): """Create ButtonInidicator Args: ----- anybar_port : Optional port to use for AnyBar """ if anybar_port: self.anybar = AnyBar(anybar_port) else: self.anybar = AnyBar() self.entered = False
class LineWatcher(object): def __init__(self): self.start_flag = False self.anybar = None def connect(self, host='localhost', port='1738'): if self.anybar: self.anybar.change('green') self.anybar = AnyBar(port=int(port), address=host) print('Connect to {host}:{port}'.format(host=host, port=int(port))) def start(self): self.start_flag = True if self.anybar: self.anybar.change('red') def stop(self): if self.start_flag: self.start_flag = False if self.anybar: self.anybar.change('green')
class LineWatcher(object): def __init__(self): self.start_flag = False self.anybar = None def connect(self, host="localhost", port="1738"): if self.anybar: self.anybar.change("green") self.anybar = AnyBar(port=int(port), address=host) print("Connect to {host}:{port}".format(host=host, port=int(port))) def start(self): self.start_flag = True if self.anybar: self.anybar.change("red") def stop(self): if self.start_flag: self.start_flag = False if self.anybar: self.anybar.change("green")
def blue(self): AnyBar().change('blue', text='Mood = Happy')
def cyan(self): AnyBar().change('cyan', text='Mood = Hopeful')
def green(self): AnyBar().change('green', text='Mood = Calm')
def yellow(self): AnyBar().change('yellow', text='Mood = Anxious') reply = QtGui.QMessageBox.information( self, "", "Why don't you try some breathing exercises?")
def orange(self): AnyBar().change('orange', text='Mood = Nervous')
def tea(): AnyBar().change('red', text="Tea ready!")
def connect(self, host="localhost", port="1738"): if self.anybar: self.anybar.change("green") self.anybar = AnyBar(port=int(port), address=host) print("Connect to {host}:{port}".format(host=host, port=int(port)))
g.tight_layout() g.savefig("diagnostics/single_page_spectra/"+str(int(i_cube))+ "_cube_"+str(cube_id)+"_spectra.pdf") plt.close("all") singular_plot() # removing data which doesn't have an O[II] doublet for us to compare to sigma_doublet_vals = data[:][:,0][:,1] sigma_doublet_zeros = np.where(sigma_doublet_vals == 0)[0] data = np.delete(data, sigma_doublet_zeros, 0) print(data) np.save("data/ppxf_fitter_data", data) # tells system to play a sound to alert that work has been finished os.system('afplay /System/Library/Sounds/Glass.aiff') personal_scripts.notifications("ppxf_fitter", "Script has finished!") if __name__ == '__main__': AnyBar().change('red') ppxf_cube_auto() #usable_cubes() #ppxf_plots.sigma_sn() #region_graphs_with_data() AnyBar().change('green')
#!/usr/bin/env python from time import sleep from anybar import AnyBar ab = AnyBar() def change(color): ab.change(color) sleep(.5) change('white') change('red') change('orange') change('yellow') change('green') change('cyan') change('blue') change('purple') change('black') change('question') change('exclamation') try: change('fdafsd') except ValueError: pass
class ButtonIndicator(object): """Class to watch Reddit's /r/thebutton and update AnyBar.""" headers = {'user-agent': 'Button_Visualizer_app/0.1.0'} BUTTON_COLORS = { 52: 'purple', 42: 'blue', 32: 'green', 22: 'yellow', 12: 'orange', 0: 'red' } def __init__(self, anybar_port=None): """Create ButtonInidicator Args: ----- anybar_port : Optional port to use for AnyBar """ if anybar_port: self.anybar = AnyBar(anybar_port) else: self.anybar = AnyBar() self.entered = False def __enter__(self): """Create context manager that allows safe polling.""" socket_url = self.get_websocket_url() self.ws = self.connect_to_socket(socket_url) self.entered = True return self def __exit__(self, type, value, traceback): self.cleanup() def run(self): """Poll webserver and update anybar.""" if not self.entered: with self as s: s.run() for time in self.read_socket_data(): self.set_anybutton_color(time) def cleanup(self): """Close port and reset AnyBar to default (white).""" self.entered = False if hasattr(self, 'ws'): self.ws.close() del self.ws print "Socket closed" self.anybar.change('white') @classmethod def get_websocket_url(cls): """Scan reddit page for websocket url.""" url = "http://www.reddit.com/r/thebutton" r = requests.get(url, headers=cls.headers) if r.ok: pattern = r'"(wss://wss.redditmedia.com/thebutton\?h=[^"]*)' found = re.search(pattern, r.content) if found: return found.group(1) return None def connect_to_socket(self, socket_url): """Create client connection to websocket.""" ws = websocket.create_connection(socket_url) print "Successfully connected to socket: {}".format(socket_url) return ws def read_socket_data(self): """Iterator to read data from websocket.""" if not hasattr(self, 'ws'): raise Exception("Websocket not created.") try: while True: result = json.loads(self.ws.recv()) yield result['payload']['seconds_left'] except: return def set_anybutton_color(self, time): """Update AnyButton with current colour or exclamation on error.""" color_index = max([k for k in self.BUTTON_COLORS if time >= k] or 0) color = self.BUTTON_COLORS.get(color_index, "exclamation") self.anybar.change(color)
def purple(self): AnyBar().change('purple', text='Mood = Nostalgic') reply = QtGui.QMessageBox.information( self, "", "Why don't you try listening to Darwin?")
conn = HTTPConnection(host='google.com', port=HTTP_PORT, timeout=1) conn.request("HEAD", "/") response = conn.getresponse() conn.close() if response.status != 301: raise tm = (time() - cur) * 1000 # to ms except: pass return tm id = 0 while True: status[id] = ping() success = 0 sum = 0 for tm in status: if tm: success += 1 sum += tm if not success: AnyBar(port=ANYBAR_PORT).change('red') elif success < QUERIES or (sum / success) > 100: AnyBar(port=ANYBAR_PORT).change('yellow') else: AnyBar(port=ANYBAR_PORT).change('green') sleep(1) id = (id + 1) % QUERIES
def black(self): AnyBar().change('black', text='Mood = Despair') reply = QtGui.QMessageBox.information( self, "", "Stop what you are doing, have a relaxing tea and watch some cat videos" )
def red(self): AnyBar().change('red', text='Mood = Sad') date = datetime.now() print(date)
def connect(self, host='localhost', port='1738'): if self.anybar: self.anybar.change('green') self.anybar = AnyBar(port=int(port), address=host) print('Connect to {host}:{port}'.format(host=host, port=int(port)))
def coffee(): AnyBar().change('purple', text="Coffee ready!")