-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
64 lines (47 loc) 路 1.63 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import sys
import os
import pytz
import datetime
import logging
from calendar_monkey.calendar import CalendarApi, create_cache
import click
import json
from calendar_monkey.config import load_config
# import time
# import atexit
log = logging.getLogger(__name__)
@click.group()
@click.option("--debug", default=False)
@click.option("--config-file", "-c", default="calendar_monkey.json", show_default=True)
@click.pass_context
def cli(ctx, debug, config_file):
ctx.ensure_object(dict)
ctx.obj["CONFIG"] = load_config(config_file)
tz = pytz.timezone(ctx.obj["CONFIG"].timezone)
ctx.obj["NOW"] = tz.localize(datetime.datetime.now())
logging_level = logging.INFO
if debug:
logging_level = logging.DEBUG
logging.basicConfig(
level=logging_level,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
@cli.command()
@click.option("--days-offset", default=0, show_default=True)
@click.option("--days", default=7, show_default=True)
@click.option("--events", default=1, show_default=True)
@click.option("--dry-run", default=False, show_default=True)
@click.pass_context
def cancel_entries(ctx, days_offset, days, events, dry_run):
cfg = ctx.obj["CONFIG"]
# date = ctx.obj['NOW'].replace(hour=0, minute=0, second=0, microsecond=0)
cache = create_cache(cfg.graph.cache_path)
calApi = CalendarApi(cfg.graph, cache, cfg.timezone)
calApi.login()
result = calApi.cancel(days_offset, days, events, dry_run)
if not result:
click.echo("cancel entries failed")
sys.exit(1)
click.echo("%s events canceled " % result)
if __name__ == "__main__":
cli(obj={})