Website content for chibug.org
1#!/usr/bin/env ruby
2#
3# Copyright (c) 2019 joshua stein <jcs@jcs.org>
4#
5# Permission to use, copy, modify, and distribute this software for any
6# purpose with or without fee is hereby granted, provided that the above
7# copyright notice and this permission notice appear in all copies.
8#
9# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16#
17
18#
19# i am incredibly lazy
20#
21
22require "date"
23require "tempfile"
24
25def find_next_2nd_tuesday(date)
26 first = Date.parse(date.strftime("%Y-%m-01"))
27
28 if first.wday <= 2
29 # 1st of the month falls on a sunday/monday, second tuesday is 1 week after
30 return first + (2 - first.wday) + 7
31 else
32 return first + (2 - first.wday) + (7 * 2)
33 end
34end
35
36def ordinal(n)
37 case n % 100
38 when 11, 12, 13
39 "th"
40 else
41 case n % 10
42 when 1
43 "st"
44 when 2
45 "nd"
46 when 3
47 "rd"
48 else
49 "th"
50 end
51 end
52end
53
54tues2 = nil
55
56if ARGV[0]
57 if ARGV[0].to_s.match(/^\d\d\d\d-\d\d-\d\d$/)
58 tues2 = Date.parse(ARGV[0])
59 else
60 puts "usage: #{$0} [YYYY-mm-dd]"
61 exit 1
62 end
63end
64
65if !tues2
66 tues2 = find_next_2nd_tuesday(Date.parse(Date.today.strftime("%Y-%m-01")))
67
68 while tues2 < Date.today
69 # assume next month
70 tues2 += 28
71 end
72end
73
74# don't start if git is not up-to-date and pushed
75system("git", "pull", "--ff-only") || raise
76system("git", "diff", "--quiet", "--exit-code", "master", "origin/master") || raise
77
78File.open(fn = "_posts/#{tues2.strftime("%Y-%m-%d")}-meeting.md", "w+") do |f|
79 f.puts <<END
80---
81layout: post
82title: "#{tues2.strftime("%B %-d")}#{ordinal(tues2.day)} Meetup"
83author: #{`whoami`.strip}
84---
85
86ChiBUG will be meeting on
87#{tues2.strftime("%A, %B %-d")}#{ordinal(tues2.day)}, #{tues2.year}
88at
896pm
90at
91our usual place:
92[Giordano's at 1115 W. Chicago Ave. in Oak Park](https://www.google.com/maps/dir//Giordano's,+1115+Chicago+Ave,+Oak+Park,+IL+60302).
93
94If you plan on attending, please post to the
95[mailing list](https://groups.io/g/chibug)
96so we can get an estimated head count.
97If you change your mind or are running late, please email the mailing list so
98we can organize accordingly.
99END
100end
101
102while true do
103 system((ENV["VISUAL"] || ENV["EDITOR"] || "/usr/bin/env vi") + " " + fn)
104
105 puts ""
106 print "(e)dit again, (c)ontinue, or ^C to abort: [c] "
107 opt = STDIN.gets.to_s.strip
108 if opt == "" || opt == "c"
109 break
110 end
111end
112
113system("git", "add", fn) || raise
114system("git", "commit",
115 "-m", "#{tues2.strftime("%Y-%m-%d")}: next meeting") || raise
116system("git", "push") || raise
117
118t = Tempfile.new
119t.puts "Our next meetup on #{tues2.strftime("%A, %B %-d")}" +
120 "#{ordinal(tues2.day)} will be at our normal "
121t.puts "location starting at 6pm:"
122t.puts ""
123t.puts "Giordano's"
124t.puts "1115 W. Chicago Ave"
125t.puts "Oak Park, IL 60302"
126t.puts ""
127t.puts "https://chibug.org/#{tues2.strftime("%Y/%m/%d")}/meeting"
128t.puts ""
129t.puts "Please reply here to the list if you plan on attending."
130t.close
131
132system(
133 "mutt",
134 "-s", "#{tues2.strftime("%B %-d")}#{ordinal(tues2.day)} Meeting",
135 "-i", t.path,
136 "chibug@groups.io"
137)
138
139File.unlink(t.path)