Repository navigation
Expand file tree
/
Copy pathdemo
More file actions
executable file
·39 lines (32 loc) · 1.79 KB
/
Copy pathdemo
File metadata and controls
executable file
·39 lines (32 loc) · 1.79 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
#!/usr/bin/env python3
"""Run the real query handlers against fictional records on a Mac."""
import json
from pathlib import Path
import sqlite3
import subprocess
from tempfile import TemporaryDirectory
root = Path(__file__).resolve().parents[1]
fixtures = root / "Tests/CommandFixtures"
with TemporaryDirectory() as work:
binary = Path(work) / "apple-cli"
subprocess.run(["xcrun", "swiftc", *sorted((root / "Sources/AppleCore").glob("*.swift")),
fixtures / "main.swift", "-o", binary], check=True)
with sqlite3.connect(Path(work) / "fixture.sqlite") as database:
database.executescript((fixtures / "reminders.sql").read_text())
def read(*args):
return json.loads(subprocess.check_output([binary, *args]))
print("Notes · Where did I write down the renewal date?")
note = read("notes", "find", "renewal date")["items"][0]
sentence = next(part for part in note["excerpt"].split(". ") if "renewal date" in part.lower())
print(note["title"], "·", sentence.strip())
print("\nReminders · What’s left on the café launch?")
task_id = read("reminders", "find", "Café launch")["items"][0]["id"]
task = read("reminders", "get", str(task_id), "--fields", "section,tags")
print(task["section"], "·", ", ".join("#" + tag for tag in task["tags"]))
for item in read("reminders", "subtasks", str(task_id))["items"]:
print("[x]" if item["completed"] else "[ ]", item["title"])
print("\nPhotos · How many videos did I mark as favorites?")
print(read("photos", "count", "--favorite", "--type", "video")["count"], "favorite videos")
print("\nContacts · What’s Sam Reed’s work email?")
card = read("contacts", "find", "Sam Reed", "--fields", "name,emails")["items"][0]
print(card["name"], "·", card["emails"][0]["value"])