2 function sfvlug_email(to, from, subj, body, sendmail)
4 from = NICK "<andy@pileus.org>"
5 subj = "Update sfvlug.org!"
6 body = "The next SFVLUG meeting is TBA!"
7 sendmail = "/usr/sbin/sendmail '" to "'"
8 print "To: " to | sendmail
9 print "From: " from | sendmail
10 print "Subject: " subj | sendmail
13 say("Topic out of date, emailing " to);
17 function sfvlug_website( curl, day, tba, ptrn, line, date, parts)
19 debug("Polling SFVLUG Website");
21 curl = "curl -s http://sfvlug.org/"
22 day = "(Sun|Mon|Tue|Wed|Thu|Fri|Sat)"
23 tba = "next meeting is: TBA"
24 ptrn = "next meeting.*" day "\\w+[, ]+([A-Z]\\w+) +([0-9]+)[, ]+([0-9]+)"
25 while (curl | getline line) {
27 debug("Website date is TBA");
28 if (match(line, ptrn, parts))
29 date = parts[1] " " parts[2] " " parts[3]
30 #sfvlug_email("Brian <brian@zimage.com>");
36 function sfvlug_meetup( url, curl, line, text, name, where, when)
38 debug("Polling SFVLUG Meetup");
40 # Signed API URL (this cannot be changed)
41 url = "http://api.meetup.com/2/events?" \
45 "limited_events=False&" \
48 "photo-host=public&" \
53 "sig=42d2f7ec48b697ba087db2d8f2c65a2f144de8b1"
56 curl = "curl -s \'" url "\'"
57 while (curl | getline line)
61 # Parse JSON and save extracted data
62 json_decode(text, events)
63 if (!isarray(events) ||
64 !isarray(events["results"]) ||
65 !isarray(events["results"][0]) ||
66 !isarray(events["results"][0]["venue"])) {
67 debug("No results from Meetup");
70 for (key in events["results"][0])
71 json_copy(sfvlug_event, key, events["results"][0][key])
74 name = sfvlug_event["name"]
75 where = sfvlug_event["venue"]["name"] " " \
76 sfvlug_event["venue"]["city"]
77 when = sfvlug_event["time"] + \
78 sfvlug_event["utc_offset"]
79 when = strftime("%a %B %d, %l:%M%P", when/1000)
80 gsub(/[.!?:]+$/, "", name)
81 gsub(/Restaurant/, "", where)
82 gsub(/ +/, " ", where)
84 debug("event: ...\n" json_encode(sfvlug_event))
87 debug("where: " where)
88 return name ": " when " " where
91 function sfvlug_update(chan)
93 # Make sure we have the current topic
95 debug("Unknown topic for " chan);
101 #text = sfvlug_website()
102 text = sfvlug_meetup()
107 update = TOPICS[chan]
108 sub(/\| [^|]+ \|/, "| " text " |", update)
109 if (update != TOPICS[chan]) {
110 topic(chan, TOPICS[chan] = update)
112 debug("topic is already correct")
118 debug("Loading SFVLUG");
119 sfvlug_channel = "#sfvlug"
121 sfvlug_event["time"] = 0
122 sfvlug_event["name"] = 0
125 (CMD == "PING" && systime()-sfvlug_polled > 60*60*24) ||
126 (CMD == "PRIVMSG" && /^\.poll/) {
127 debug("Updating SFVLUG topic")
128 sfvlug_update(sfvlug_channel)
129 sfvlug_polled = systime()
133 if (!sfvlug_meetup()) {
134 say("Error looking up meeting")
138 _name = sfvlug_event["name"]
139 _desc = sfvlug_event["description"]
140 _where = sfvlug_event["venue"]["name"] ", " \
141 sfvlug_event["venue"]["city"] ", " \
142 sfvlug_event["venue"]["state"] ", " \
143 sfvlug_event["venue"]["zip"]
144 _when = sfvlug_event["time"] + \
145 sfvlug_event["utc_offset"]
146 _when = strftime("%a %B %d, %l:%M%P", _when/1000)
147 _desc = gensub(/<[^>]*>/, "", "g", _desc);
148 _desc = gensub(/\\(.)/, "\\1", "g", _desc);
150 say("Next meeting: " _name)
152 say("Location: " _where)
153 say("Details: " _desc)