- Running macOS
- things.sh installed.
Created
March 1, 2021 21:33
-
-
Save dustinknopoff/82651987c829f6d67d08585e53f2dcb6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env/bash | |
./events-today | |
echo "" | |
python3 things.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// events-today.swift | |
// calendar | |
// | |
// Created by Dustin Knopoff on 11/5/20. | |
// | |
// NOTE: Cannot be run inside Xcode | |
import Foundation | |
import EventKit | |
let store = EKEventStore() | |
store.requestAccess(to: .event) { (granted, error) in | |
if let error = error { | |
print("error: \(error.localizedDescription)") | |
} else { | |
// print("authorization granted!") | |
} | |
} | |
let calendars = store.calendars(for: .event) | |
// Get the appropriate calendar. | |
var calendar = Calendar.current | |
// Create the start date components | |
let startOfDay = calendar.startOfDay(for: Date()) | |
var endOfDay: Date { | |
var components = DateComponents() | |
components.day = 1 | |
components.second = -1 | |
return Calendar.current.date(byAdding: components, to: startOfDay)! | |
} | |
var startOfMonth: Date { | |
let components = Calendar.current.dateComponents([.year, .month], from: startOfDay) | |
return Calendar.current.date(from: components)! | |
} | |
var endOfMonth: Date { | |
var components = DateComponents() | |
components.month = 1 | |
components.second = -1 | |
return Calendar.current.date(byAdding: components, to: startOfMonth)! | |
} | |
let mediumDateFormatter: DateFormatter = { | |
let df = DateFormatter() | |
df.dateStyle = .medium | |
df.timeStyle = .none | |
return df | |
}() | |
print("# \(mediumDateFormatter.string(from: Date()))\n") | |
print("## Calendar Events\n") | |
let df = DateFormatter() | |
df.dateStyle = .none | |
df.timeStyle = .medium | |
let predicate = store.predicateForEvents(withStart: startOfDay, end: endOfDay, calendars: calendars) | |
var events = store.events(matching: predicate) | |
for event in events { | |
if event.isAllDay { continue } | |
let title = event.title! | |
let start = df.string(from: event.startDate!) | |
let end: String = { | |
if event.endDate != nil { | |
return df.string(from: event.endDate!) | |
} else { | |
return String() | |
} | |
}() | |
print("- \(title) \(start)-\(end)") | |
} | |
print("\n## Tasks") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
arg = ["/usr/local/bin/things.sh", "today"] | |
p = subprocess.Popen(arg, stdout=subprocess.PIPE, | |
stderr=subprocess.STDOUT) | |
(stdout,stderr) = p.communicate() | |
tasks = stdout.decode() | |
for task in tasks.split("\n"): | |
if len(task) > 1: | |
[project, task, link] = task.split("|") | |
print(f"- {str(task)}: {str(project)} [link]({str(link)}) \n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment