def dragon_greet(): print("_______________________________________________________________\n") time = datetime.datetime.now().time() global user_full_name global user_prefix global config_file command = "getent passwd $LOGNAME | cut -d: -f5 | cut -d, -f1" user_full_name = os.popen(command).read() user_full_name = user_full_name[:-1] # .decode("utf8") home = expanduser("~") config_file = TinyDB(home + '/.dragonfire_config.json') callme_config = config_file.search(Query().datatype == 'callme') if callme_config: user_prefix = callme_config[0]['title'] else: gender_config = config_file.search(Query().datatype == 'gender') if gender_config: user_prefix = GENDER_PREFIX[gender_config[0]['gender']] else: gender = Classifier.gender(user_full_name.split(' ', 1)[0]) config_file.insert({'datatype': 'gender', 'gender': gender}) user_prefix = GENDER_PREFIX[gender] if time < datetime.time(12): time_of_day = "morning" elif datetime.time(12) < time < datetime.time(18): time_of_day = "afternoon" else: time_of_day = "evening" userin.execute(["echo"], "To activate say 'Dragonfire!' or 'Wake Up!'") userin.say(" ".join(["Good", time_of_day, user_prefix]))
def greet(userin): """The top-level method to greet the user with message like "*Good morning, sir.*". Args: userin: :class:`dragonfire.utilities.TextToAction` instance. Returns: str: Response. """ (columns, lines) = shutil.get_terminal_size() print(columns * "_" + "\n") time = datetime.datetime.now().time() global user_full_name global user_prefix global config_file command = "getent passwd $LOGNAME | cut -d: -f5 | cut -d, -f1" user_full_name = os.popen(command).read() user_full_name = user_full_name[:-1] # .decode("utf8") home = expanduser("~") config_file = TinyDB(home + '/.dragonfire_config.json') callme_config = config_file.search(Query().datatype == 'callme') if callme_config: user_prefix = callme_config[0]['title'] else: gender_config = config_file.search(Query().datatype == 'gender') if gender_config: user_prefix = GENDER_PREFIX[gender_config[0]['gender']] else: gender = Classifier.gender(user_full_name.split(' ', 1)[0]) config_file.insert({'datatype': 'gender', 'gender': gender}) user_prefix = GENDER_PREFIX[gender] if datetime.time(4) < time < datetime.time(12): time_of_day = "morning" elif datetime.time(12) < time < datetime.time(18): time_of_day = "afternoon" elif datetime.time(18) < time < datetime.time(22): time_of_day = "evening" else: time_of_day = "night" userin.execute(["echo"], "To activate say 'Dragonfire!' or 'Wake Up!'") return userin.say(" ".join(["Good", time_of_day, user_prefix]))
def greet(userin): """The top-level method to greet the user with message like "*Good morning, sir.*". Args: userin: :class:`dragonfire.utilities.TextToAction` instance. Returns: str: Response. """ (columns, lines) = shutil.get_terminal_size() print(columns * "_" + "\n") time = datetime.datetime.now().time() global user_full_name global user_prefix global config_file command = "getent passwd $LOGNAME | cut -d: -f5 | cut -d, -f1" user_full_name = os.popen(command).read() user_full_name = user_full_name[:-1] # .decode("utf8") home = expanduser("~") config_file = TinyDB(home + '/.dragonfire_config.json') callme_config = config_file.search(Query().datatype == 'callme') if callme_config: user_prefix = callme_config[0]['title'] else: gender_config = config_file.search(Query().datatype == 'gender') if gender_config: user_prefix = GENDER_PREFIX[gender_config[0]['gender']] else: gender = Classifier.gender(user_full_name.split(' ', 1)[0]) config_file.insert({'datatype': 'gender', 'gender': gender}) user_prefix = GENDER_PREFIX[gender] if time < datetime.time(12): time_of_day = "morning" elif datetime.time(12) < time < datetime.time(18): time_of_day = "afternoon" else: time_of_day = "evening" userin.execute(["echo"], "To activate say 'Dragonfire!' or 'Wake Up!'") return userin.say(" ".join(["Good", time_of_day, user_prefix]))
def test_classifier_gender(name, gender): assert Classifier.gender(name) == gender