-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathcli.py
More file actions
48 lines (41 loc) · 1.24 KB
/
Copy pathcli.py
File metadata and controls
48 lines (41 loc) · 1.24 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
import click
from homework.patient import *
@click.group()
def cli():
pass
@cli.command()
@click.argument('first_name')
@click.argument('last_name')
@click.option('--birth_date', '-a')
@click.option('--phone', '-a')
@click.option('--document_type', '-a')
@click.option('--document_id', '-a')
def create(first_name, last_name, birth_date, phone, document_type, document_id):
test = Patient(first_name, last_name, birth_date, phone, document_type, document_id)
test.save()
click.echo("Создан новый пациент")
@cli.command()
@click.argument('value' , default = 10 )
def show(value):
collection = PatientCollection()
if value == 10:
for patient in collection.limit(value):
click.echo(patient)
else:
for patient in collection.limit(value):
click.echo(patient)
@cli.command()
def count():
count = 0
var = pymysql.connect(host='localhost', port=3306, user='root', passwd='passwd',
db='forpat')
conn = var.cursor(pymysql.cursors.DictCursor)
conn.execute("SELECT * FROM patiens")
rows = conn.fetchall()
for row in rows:
count = count + 1
conn.close()
var.close()
click.echo(count)
if __name__ == '__main__':
cli()