-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGenerate syllabus table in Markdown - multi-line.applescript
109 lines (100 loc) · 3.62 KB
/
Generate syllabus table in Markdown - multi-line.applescript
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
(* Generate syllabus table in Markdown
by Derick Fay, March 2015
this version generates tables:
Week 1
Day 1
Day 2 *)
set noWeeks to 10 -- 10 week course
set theDays to "mwf" -- Tuesday and Thursday
-- options are m, t, w, r, f, s, u
set theStart to date "Monday, March 30, 2015 at 12:00:00 AM" -- Monday of the week courses start
set theHolidays to {date "Wednesday, May 27, 2015 at 12:00:00 AM"}
-- leave everything below here alone
set theString to "|Course Schedule|
|-|-|-|
"
set theColumns to "| |
" --the blank column for the Week
set currentClass to 1
repeat with n from 1 to noWeeks
set theString to theString & "|**Week " & (n as string) & "**| |
"
if theDays contains "m" then
set theDate to theStart + ((n - 1) * 7 * 86400)
set theString to (theString & "|" & (((weekday of theDate as string)) & " " & month of theDate as string) & " " & day of theDate as string) & "|"
if check(theDate, theHolidays) then
set theString to theString & "**No Class**"
end if
set currentClass to currentClass + 1
set theString to theString & " |
"
end if
if theDays contains "t" then
set theDate to theStart + ((n - 1) * 7 * 86400) + 86400
set theString to (theString & "|" & (((weekday of theDate as string)) & " " & month of theDate as string) & " " & day of theDate as string) & "|"
if check(theDate, theHolidays) then
set theString to theString & "**No Class**"
end if
set currentClass to currentClass + 1
set theString to theString & " |
"
end if
if theDays contains "w" then
set theDate to theStart + ((n - 1) * 7 * 86400) + (2 * 86400)
set theString to (theString & "|" & (((weekday of theDate as string)) & " " & month of theDate as string) & " " & day of theDate as string) & "|"
if check(theDate, theHolidays) then
set theString to theString & "**No Class**"
end if
set currentClass to currentClass + 1
set theString to theString & " |
"
end if
if theDays contains "r" then
set theDate to theStart + ((n - 1) * 7 * 86400) + (3 * 86400)
set theString to (theString & "|" & (((weekday of theDate as string)) & " " & month of theDate as string) & " " & day of theDate as string) & "|"
if check(theDate, theHolidays) then
set theString to theString & "**No Class**"
end if
set currentClass to currentClass + 1
set theString to theString & " |
"
end if
if theDays contains "f" then
set theDate to theStart + ((n - 1) * 7 * 86400) + (4 * 86400)
set theString to (theString & "|" & (((weekday of theDate as string)) & " " & month of theDate as string) & " " & day of theDate as string) & "|"
if check(theDate, theHolidays) then
set theString to theString & "**No Class**"
end if
set currentClass to currentClass + 1
set theString to theString & " |
"
end if
if theDays contains "s" then
set theDate to theStart + ((n - 1) * 7 * 86400) + (5 * 86400)
set theString to (theString & "|" & (((weekday of theDate as string)) & " " & month of theDate as string) & " " & day of theDate as string) & "|"
if check(theDate, theHolidays) then
set theString to theString & "**No Class**"
end if
set currentClass to currentClass + 1
set theString to theString & " |
"
end if
if theDays contains "u" then
set theDate to theStart + ((n - 1) * 7 * 86400) + (6 * 86400)
set theString to (theString & "|" & (((weekday of theDate as string)) & " " & month of theDate as string) & " " & day of theDate as string) & "|"
if check(theDate, theHolidays) then
set theString to theString & "**No Class**"
end if
set currentClass to currentClass + 1
set theString to theString & " |
"
end if
end repeat
set the clipboard to theString
on check(d, h)
if h is in d then
true
else
false
end if
end check