def internet_func(args): from irkit.api import InternetAPI if args.verbose: from logging import DEBUG from irkit import logger, handler handler.setLevel(DEBUG) logger.setLevel(DEBUG) api = InternetAPI() # if args.keys: # print(api.keys.post()) # print('this is your key') # return if args.send: key = args.client_key if key is None: return print("retrieve over the internet needs client-key") print("key is ", key) device_id = args.device_id if key is None: return print("retrieve over the internet needs device-id") print("device id is ", device_id) # FIXME: I hate this style value_to_send = None try: # TODO: check parsable before load value_to_send = json.loads(args.send) except ValueError: # if argument is just string this command assume that is key name of data store try: value_to_send = get_signals()[args.send] except (IOError, KeyError): return print('invalid name "{}" is passed. string should be key of signal.json'.format(args.send)) result = api.messages.post(value_to_send, key, device_id) print("") return print("signal was sent") elif args.retrieve: key = args.client_key if key is None: return print("retrieve over the internet needs client-key") result = api.messages.get(key) if result.is_empty(): return print("retrieve empty data. you should send signal to irkit before retrieve.") if args.save: save_signal(args.save, result.as_dict()) print("save signal as {} in ~/.config/irkit-py/signal.json".format(args.save)) print(str(result)) return else: print("need argument. see help") return
def local_func(args): from irkit.api import LocalAPI if args.verbose: from logging import DEBUG from irkit import logger, handler handler.setLevel(DEBUG) logger.setLevel(DEBUG) if args.list: for s in get_signals(): print(s) return base_uri = resolve_irkit_addresses()[0] if args.host: print(base_uri) return api = LocalAPI(base_uri) if args.keys: print(api.keys.post()) print("this is your key") return elif args.send: # FIXME: I hate this style value_to_send = None try: # TODO: check parsable before load value_to_send = json.loads(args.send) except ValueError: # if argument is just string this command assume that is key name of data store try: value_to_send = get_signals()[args.send] except (IOError, KeyError): return print('invalid name "{}" is passed. string should be key of signal.json'.format(args.send)) result = api.messages.post(value_to_send) print("") return print("signal was sent") elif args.retrieve: result = api.messages.get() if result.is_empty(): return print("retrieve empty data. you should send signal to irkit before retrieve.") if args.save: save_signal(args.save, result.as_dict()) print("save signal as {} in ~/.config/irkit-py/signal.json".format(args.save)) print(str(result)) return else: print("need argument. see help") return
def local_func(args): from irkit.api import LocalAPI if args.verbose: from logging import DEBUG from irkit import logger, handler handler.setLevel(DEBUG) logger.setLevel(DEBUG) if args.list: for s in get_signals(): print(s) return base_uri = resolve_irkit_addresses()[0] if args.host: print(base_uri) return api = LocalAPI(base_uri) if args.keys: print(api.keys.post()) print('this is your key') return elif args.send: # FIXME: I hate this style value_to_send = None try: # TODO: check parsable before load value_to_send = json.loads(args.send) except ValueError: # if argument is just string this command assume that is key name of data store try: value_to_send = get_signals()[args.send] except (IOError, KeyError): return print( 'invalid name "{}" is passed. string should be key of signal.json' .format(args.send)) result = api.messages.post(value_to_send) print('') return print('signal was sent') elif args.retrieve: result = api.messages.get() if result.is_empty(): return print( 'retrieve empty data. you should send signal to irkit before retrieve.' ) if args.save: save_signal(args.save, result.as_dict()) print('save signal as {} in ~/.config/irkit-py/signal.json'.format( args.save)) print(str(result)) return else: print('need argument. see help') return
def internet_func(args): from irkit.api import InternetAPI if args.verbose: from logging import DEBUG from irkit import logger, handler handler.setLevel(DEBUG) logger.setLevel(DEBUG) api = InternetAPI() # if args.keys: # print(api.keys.post()) # print('this is your key') # return if args.send: key = args.client_key if key is None: return print('retrieve over the internet needs client-key') print('key is ', key) device_id = args.device_id if key is None: return print('retrieve over the internet needs device-id') print('device id is ', device_id) # FIXME: I hate this style value_to_send = None try: # TODO: check parsable before load value_to_send = json.loads(args.send) except ValueError: # if argument is just string this command assume that is key name of data store try: value_to_send = get_signals()[args.send] except (IOError, KeyError): return print( 'invalid name "{}" is passed. string should be key of signal.json' .format(args.send)) result = api.messages.post(value_to_send, key, device_id) print('') return print('signal was sent') elif args.retrieve: key = args.client_key if key is None: return print('retrieve over the internet needs client-key') result = api.messages.get(key) if result.is_empty(): return print( 'retrieve empty data. you should send signal to irkit before retrieve.' ) if args.save: save_signal(args.save, result.as_dict()) print('save signal as {} in ~/.config/irkit-py/signal.json'.format( args.save)) print(str(result)) return else: print('need argument. see help') return