-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
95 lines (75 loc) · 2.66 KB
/
Copy pathcli.py
File metadata and controls
95 lines (75 loc) · 2.66 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import sys
from db.models import Things, Events, Notes
from datetime import datetime, timedelta
"""
v0 run w/: $ python3 -m cli.main [args]
"""
"""
args:
event [thing_name] [starttime] [endtime=None] [place=None] [duration=None]
-> triggers newEvent
-> asks for Note
-> if yes
- -> opens note.txt in shell text editor
- -> upon save/exit -> triggers Event.newNote(session, content=read(note.txt))
note [thing_names]
-> opens note.txt in shell text editor
-> upon save/exit -> triggers Note.newNote(session, thing_names=[thing_names], content=read(note.txt)
"""
"""
Development Mode: Use Test DB
"""
development = True
# if development:
# from db.db import create_session
# engine, Session = create_session("postgresql://localhost/test-whid.v0")
# else:
from db.db import Session
session = Session()
def invalid_input(*args):
"""Handles Invalid Input Argument"""
print(f"Invalid Action: {sys.argv[1]}")
print("Action must be in [event, note]")
def new_event(*args):
"""New Event Input"""
#Events.newEvent(cls, session, thing_name, starttime=None, endtime=None, place=None)
#Events.newNote(self, session, content)
# Most Basic Input: Just Thing Name
# Next Level: Duration and/or Place
# Next Level: Update Default Duration and/or Place
print('creating new event\n')
event = Events.newEvent(session, thing_name=args[0]) #ugly, use kwargs?
print(event.thing.name, event.id)
print('\n')
def new_note(*args):
"""New Note Input"""
#Notes.newNote(cls, session, thing_names=[], thing_ids=[], content=None)
print('creating new note')
def list_things(*args):
"""Lists Things"""
dayrange = args['dayrange'] if 'dayrange' in args else 14
print("Things You're Doing:\n")
today = datetime.today().date()
daterange = [today - timedelta(days=i) for i in range(dayrange, -1, -1)]
for thing in session.query(Things).all():
line = thing.name + " "*(20 - len(thing.name))
event_dates = set(event.starttime.date() for event in session.query(Events.starttime).filter(Events.thing_id == thing.id).all() if event.starttime != None)
line += " ".join(["X" if day in event_dates else "_" for day in daterange])
# " " if
print(line)
# print("\n".join(thing.name for thing in session.query(Things).all()))
"""
Other Functions
List Events/Notes By Thing
"""
from collections import defaultdict
switcher = defaultdict(lambda: invalid_input)
switcher['event'] = new_event
switcher['note'] = new_note
switcher['things'] = list_things
if __name__ == "__main__":
print('whid called\n')
try:
switcher[sys.argv[1]](*sys.argv[2:])
except IndexError:
print('No Actions Taken')