def generic_handler(ts, key, data): """ Generic handler to broadcast message to all peers, custom handlers can be created by func name handler_<event_name> Ex: handle_event_volume_create(ts, key, data) """ utils.publish(ts, key, data)
def handle_event_volume_set(ts, key, data): """ Recieved data will have all the options as one string, split into list of options. "key1,value1,key2,value2" into [[key1, value1], [key2, value2]] """ opts = data.get("options", "").strip(",").split(",") data["options"] = [] for i, opt in enumerate(opts): if i % 2 == 0: # Add new array with key data["options"].append([opt]) else: # Add to the last added array data["options"][-1].append(opt) utils.publish(ts, key, data)
def brew(coffee_type, db): if bottle.request.headers.environ.get("REMOTE_ADDR") != "127.0.0.1": return json_return(403, "Can only start a brew from the monitor host - sorry.") data = db.execute("select id, name from coffees") coffees = {row["id"]: row["name"] for row in data} if coffee_type not in coffees.keys(): return json_return(403, "Invalid coffee type.") row = db.execute("select dts, coffee from raw_log order by dts desc").fetchone() now = datetime.datetime.now() if row: dt = datetime.datetime.strptime(row["dts"], "%Y-%m-%d %H:%M:%S") delta = now - dt if delta.seconds < BREW_TIME: if coffee_type != row["coffee"]: db.execute('update raw_log set coffee=%d where dts="%s"' % (coffee_type, row["dts"])) return json_return(200, "brew type changed. Estimated completion: %s" % estimate_complete(dt)) else: return json_return(200, "brew already in progress. Estimated completion: %s" % estimate_complete(dt)) db.execute("insert into raw_log (coffee) values (%d)" % coffee_type) eta = estimate_complete(now) ret_str = "Brew started: %s. Estimated completion: %s" % (coffees[coffee_type], eta) tweet(ret_str) publish( json.dumps( { "human": ret_str, "type": "start", "coffee": coffees[coffee_type], "start": now.strftime("%Y%m%d%H%M%S"), "estimate": eta.strftime("%Y%m%d%H%M%S"), } ) ) os.system("(%s/followup.sh %d %s)&" % (os.path.dirname(__file__), BREW_TIME, coffees[coffee_type])) return json_return(200, ret_str)
def test_example_459(): result = publish("""[link](/uri "title")""") assert_node(result, [nodes.document, nodes.paragraph, nodes.reference, "link"]) assert_node(result[0][0], refuri="/uri", reftitle='title')
def test_example_474(): result = publish("[link](foo%20bä)") assert_node(result, [nodes.document, nodes.paragraph, nodes.reference, "link"]) assert_node(result[0][0], refuri="foo%20b%C3%A4")
def test_example_172(): result = publish("[foo]: /url") assert_node(result, [nodes.document, nodes.target])
def test_example_175(): text = ('[foo]: /url\n' '"title" ok\n') result = publish(text) assert_node(result, [nodes.document, (nodes.target, [nodes.paragraph, '"title" ok'])])
def test_example_114_2(): text = ("~~~ aa ``` ~~~\n" "foo\n" "~~~\n") result = publish(text) assert_node(result, [nodes.document, nodes.literal_block, "foo\n"])
def test_example_14(): result = publish("+++") assert_node(result, [nodes.document, nodes.paragraph, "+++"])
def test_example_66(): text = ("\n" "====\n") result = publish(text) assert_node(result, [nodes.document, nodes.paragraph, "===="])
def test_example_107(): text = ("``` ```\n" "aaa\n") result = publish(text) assert_node(result, [nodes.document, nodes.paragraph, (nodes.literal, "\naaa")])
def test_example_62(): text = ("> foo\n" "bar\n" "===\n") result = publish(text) assert_node(result, [nodes.document, nodes.block_quote, nodes.paragraph, "foo\nbar\n==="])
def test_example_63(): text = ("- Foo\n" "---\n") result = publish(text) assert_node(result, [nodes.document, ([nodes.bullet_list, nodes.list_item, "Foo"], nodes.transition)])
def test_example_61(): text = ("> Foo\n" "---\n") result = publish(text) assert_node(result, [nodes.document, ([nodes.block_quote, nodes.paragraph, "Foo"], nodes.transition)])
def test_example_59(): text = ("Foo\\\n" "----\n") result = publish(text) assert_node(result, [nodes.document, nodes.section, nodes.title, "Foo\\"])
def test_example_56(): text = ("Foo\n" " ---\n") result = publish(text) assert_node(result, [nodes.document, nodes.paragraph, "Foo\n---"])
def test_example_45(): result = publish("# foo#") assert_node(result, [nodes.document, nodes.section, nodes.title, "foo#"])
def test_example_67(): text = ("---\n" "---\n") result = publish(text) assert_node(result, [nodes.document, (nodes.transition, nodes.transition)])
def test_example_95(): result = publish("```") assert_node(result, [nodes.document, nodes.literal_block])
def test_example_6(): result = publish(">\t\tfoo\n") assert_node(result, [nodes.document, nodes.block_quote, nodes.literal_block, " foo\n"])
def test_example_114(): text = ("``` aa ```\n" "foo\n") result = publish(text) assert_node(result, [nodes.document, nodes.paragraph, ([nodes.literal, "aa"], "\nfoo")])
def test_example_76(): text = (" a simple\n" " indented code block\n") result = publish(text) assert_node(result, [nodes.document, nodes.literal_block, "a simple\n indented code block\n"])
def test_example_115(): text = ("```\n" "``` aaa\n" "```\n") result = publish(text) assert_node(result, [nodes.document, nodes.literal_block, "``` aaa\n"])
def test_example_81(): text = (" chunk1\n" " \n" " chunk2\n") result = publish(text) assert_node(result, [nodes.document, nodes.literal_block, "chunk1\n \n chunk2\n"])
def test_example_16(): text = ("--\n" "**\n" "__\n") result = publish(text) assert_node(result, [nodes.document, nodes.paragraph, "--\n**\n__"])
def test_example_82(): text = ("Foo\n" " bar\n") result = publish(text) assert_node(result, [nodes.document, nodes.paragraph, "Foo\nbar"])
def test_example_174(): result = publish('[foo]: /url "title" ok') assert_node(result, [nodes.document, nodes.paragraph, '[foo]: /url "title" ok'])
def test_example_83(): text = (" foo\n" "bar\n") result = publish(text) assert_node(result, [nodes.document, ([nodes.literal_block, "foo\n"], [nodes.paragraph, "bar"])])
def test_example_2(): result = publish(" \tfoo\tbaz\t\tbim") assert_node(result, [nodes.document, nodes.literal_block, "foo\tbaz\t\tbim"])
#!/usr/bin/env python from utils import tweet, publish from datetime import datetime from time import sleep import json import sys try: cmd = sys.argv.pop(0) delay = int(sys.argv.pop(0)) coffee = sys.argv.pop(0) except: print "usage: %s delay coffee" % cmd sys.exit(1) sleep(delay) msg = "A pot of %s is ready for you. [%s]" % (coffee, datetime.now().strftime("%Y-%m-%d %H:%M:%S")) tweet(msg) publish( json.dumps(({"type": "complete", "coffee": coffee, "end": datetime.now().strftime("%Y%m%d%H%M%S"), "human": msg})) )
def test_example_473(): result = publish("[link](foo\\bar)") assert_node(result, [nodes.document, nodes.paragraph, nodes.reference, "link"]) assert_node(result[0][0], refuri="foo%5Cbar")
def test_example_90(): text = ("``\n" "foo\n" "``\n") result = publish(text) assert_node(result, [nodes.document, nodes.paragraph, nodes.literal, "foo"])
def test_example_7(): result = publish("-\t\tfoo\n") assert_node(result, [nodes.document, nodes.bullet_list, nodes.list_item, nodes.literal_block, " foo\n"])
def test_example_42(): text = ("# foo ##################################\n" "##### foo ##\n") result = publish(text) assert_node(result, [nodes.document, ([nodes.section, ([nodes.title, "foo"], [nodes.section, nodes.title, "foo"])])])