def execute(arguments, ui=user_interface.CLI, brk=broker.Broker()): """ Execute ftw_compatible_tool. Arguments: - arguments: A string list fo the arguments for pywb. - ui: A class inherited from user_interface.Interactor. This will be used for output and interaction. - brk: A Broker object. Pass this into execute if you have your own subscriber or publisher. """ ctx = context.Context(brk, delimiter=traffic.Delimiter("magic")) ui = ui(ctx) brk.publish(broker.TOPICS.SHOW_UI, "welcome") brk.publish(broker.TOPICS.SHOW_UI, "tutorial") traffic.RawRequestCollector(ctx) traffic.RawResponseCollector(ctx) traffic.RealTrafficCollector(ctx) log.LogCollector(ctx) base.Base(ctx) args = parse(arguments) database.Sqlite3DB(ctx, args.database) if args.interact: ui.interact() else: commands = args.execute.strip().split("|") for command in commands: brk.publish(broker.TOPICS.COMMAND, *tuple(shlex.split(command)))
def main(): try: the_broker = broker.Broker() the_broker.run() except KeyboardInterrupt: print("Ctrl C - Stopping.") # noinspection PyUnboundLocalVariable the_broker.stop() # noinspection PyUnusedLocal the_broker = None sys.exit(1)
def main(): logger.debug('CML server starting...') es_logger.info("CML server starting...") command_broker = broker.Broker() client = mqtt.MqttClient(command_broker) client.init() command_broker.init_commands(client) logger.info("\nAvailable commands:\n===================\n{}".format( command_broker.describe_commands())) httpd.start_httpd(command_broker, client) logger.info('Cleanup...') client.cleanup()
def __init__(self, money, init_stocks): self.money = money self.stocks = init_stocks self.keepTrading = True # This field can be changed by keyboard press self.broker = brkr.Broker() self.is_in_trading_cycle = False
try: command_buffer = shlex.split(command_buffer) except ValueError as e: print(e) try: self._ctx.broker.publish(broker.TOPICS.COMMAND, *command_buffer) except TypeError as e: print(e) if __name__ == "__main__": import testdata ctx = context.Context( broker.Broker(), delimiter=traffic.Delimiter("334787923864975794240893756898805143302")) ui = CLI(ctx) traffic.RawRequestCollector(ctx) traffic.RawResponseCollector(ctx) traffic.RealTrafficCollector(ctx) ctx.broker.publish(broker.TOPICS.SHOW_UI, "welcome") ctx.broker.publish(broker.TOPICS.CHECK_RESULT, { "output": { "a": "b", "b": "c", }, "title": "title" }, {
buys = list(filter((lambda x: x['Type'] == 'Buy'), usertx)) sells = list(filter((lambda x: x['Type'] == 'Sell'), usertx)) totals_buys = list(map((lambda x: x['Total']), buys)) totals_sells = list(map((lambda x: x['Total']), sells)) total_buy = reduce((lambda x, y: x + y), totals_buys) total_sell = reduce((lambda x, y: x + y), totals_sells) print("total buy %.1f" % total_buy) print("total sell %.1f" % total_sell) vwap_buy = 0 for buy in buys: vwap_buy += buy['Rate'] * buy['Total'] / total_buy vwap_sell = 0 for sell in sells: vwap_sell += sell['Rate'] * sell['Total'] / total_sell print(vwap_buy) print(vwap_sell) if __name__ == '__main__': #logpath = '/tmp/log' logpath = './log' log = setup_logger(logpath, 'info_logger', 'arch') abroker = broker.Broker() arch.setClientsFromFile(abroker) analyse(abroker)
def __init__(self, name): self.lock = threading.Lock() self.broker = broker.Broker(name) self.on_monitoring = False self.handlers = [] self.signal = 0x00
def on_msg(x): data = json.loads(x.payload) print "msg", data global state state = not state meter.set_relay(state) def on_state(x): data = json.loads(x.payload) print "state", data global state state = data mqtt = broker.Broker("uif", server="mosquitto") mqtt.subscribe("uif/button/1", on_msg) mqtt.subscribe("node/jeenet/7/relay", on_state) mqtt.start() while True: try: time.sleep(1) except KeyboardInterrupt: break mqtt.stop() mqtt.join() # FIN
import broker from os import walk b = broker.Broker() b.start() print('starting producer...') for (dirpath, dirnames, filenames) in walk('./input'): for fileName in filenames: with open('./input/' + fileName, 'rb') as f: b.push(f.read(), 'name=' + fileName, isByteData=True)
import user import broker import random import seller try: while True: print("Assign any of the following role:") print("Press 1 for USER") print("Press 2 for Broker") print("Press 3 for seller") userInp = raw_input("Enter your selection: ") if(userInp == '1'): brInfo = raw_input("Enter Broker's IP address & port (format:-ipaddress:port): ") ip = brInfo.split(':')[0] port = brInfo.split(':')[1] id = random.randint(10,100) # @ReservedAssignment user1 = user.User(ip,port,"C"+str(id)) elif(userInp == '2'): broker1 = broker.Broker() elif(userInp == '3'): id = random.randint(10,100) # @ReservedAssignment seller1 = seller.Seller("S"+str(id)) else: print("Invalid Input, Try Again") except Exception as e: print e