-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.py
49 lines (33 loc) · 1.04 KB
/
cli.py
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
49
from dotenv import load_dotenv
from slotter import Slotter
import click, sys, os
# load the .env variables
load_dotenv()
session_id = os.environ.get("INTRA_SESSION_ID")
if not session_id:
print("Please add your INTRA session id!", file=sys.stderr)
sys.exit(1)
# create an instance from Slotter class
slotter = Slotter(session_id)
# login with session intra and check if valid
if not slotter.login():
print("Please add a valid INTRA session id!", file=sys.stderr)
sys.exit(1)
@click.group()
def cli():
"Slotter Command line interface."
def validate_duration(ctx, param, value):
if value < 30:
raise click.BadParameter('duration should be greate than 30.')
return value
@cli.command
@click.option("--duration", "-d", type=int, callback=validate_duration, default=30)
def take_slots(duration):
"""take the untaken slots"""
slotter.take_slots(duration)
@cli.command
def delete_slots():
"""delete the taken slots"""
slotter.delete_slots()
if __name__ == "__main__":
cli(prog_name='slotter')