-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathhello_world.py
More file actions
35 lines (23 loc) · 973 Bytes
/
hello_world.py
File metadata and controls
35 lines (23 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import typer
from datetime import datetime
app = typer.Typer()
def get_name(name_file: str) -> str:
with open(name_file) as file_stream:
return file_stream.read().strip()
def get_greeting_message(chat_file: str) -> str:
return "Nice to meet you."
@app.command()
def hello(name_file: str = typer.Option(..., '--name'), chat_file: str = typer.Option(..., '--chat')):
greeting_message: str = get_greeting_message(chat_file)
with open(chat_file, 'a') as chat_stream:
chat_stream.write('[{}] Hi, {}! {}\n'.format(
datetime.now(),
get_name(name_file),
greeting_message
))
@app.command()
def bye(name_file: str = typer.Option(..., '--name'), chat_file: str = typer.Option(..., '--chat')):
with open(chat_file, 'a') as chat_stream:
chat_stream.write('[{}] Bye, {}! It was great talking to you.\n'.format(datetime.now(), get_name(name_file)))
if __name__ == '__main__':
app()