<commit_before>require 'icalendar'
require 'net/http'
require 'json'

$endpoint = ""

def notify(e, starts_in)
	events = URI('https://calendar.csail.mit.edu/event_calendar')
	lines = Net::HTTP.get(events).split("\n").select { |line| line.include? e.summary }
	# we'll get two hits, a div and the link
	href = URI.join(events, /href="([^"]*)"/.match(lines[1])[1])
	rinfo = Net::HTTP.get(href).scan(/<p>\s*<strong>(.*?):?<\/strong>(.*?)<\/p>/m)
	info = {}
	rinfo.each do |i|
		info[i[0]] = i[1]
			.gsub(/<br( \/)?>/, "\n")
			.strip
			.gsub(/\s+/, " ")
			.gsub(/\s,/, ",")
	end

	update = {
		:text => sprintf("The following talk starts in %d minutes in %s", starts_in/60, e.location),
		:channel => "#seminars",
		:username => "seminar-bot",
		:icon_emoji => ":ear:",
		:attachments => [
			{
				:author_name => info["Speaker"],
				:title => e.summary,
				:text => e.description,
				:fields => [
					{
						:title => "Room",
						:value => e.location,
						:short => true
					},
					{
						:title => "Time",
						:value => info["Time"],
						:short => true
					},
					{
						:title => "Host",
						:value => info["Host"],
						:short => true
					},
					{
						:title => "Refreshments",
						:value => info["Refreshments"],
						:short => true
					}
				]
			}
		]
	}
	if info["Relevant URL"] != "" then
		update[:attachments][:title_link] = info["Relevant URL"]
	end

	uri = URI($endpoint)
	res = Net::HTTP.post_form(uri, 'payload' => JSON.generate(update))
	puts res.body
end

begin
	$endpoint = File.open "endpoint.cfg", &:readline
rescue
	abort "endpoint.cfg not found: put the Slack Webhook URL in endpoint.cfg"
end

last = ""
notified = true
while true do
	events = URI('https://calendar.csail.mit.edu/event_calendar.ics')
	response = Net::HTTP.get(events)

	cal = Icalendar.parse(response)
	upcoming = cal.first.events.first
	if last != upcoming.summary then
		last = upcoming.summary
		notified = false
	end
	starts_in = upcoming.dtstart.value.to_time - Time.now

	printf("next event: %s starts in %d minutes\n", upcoming.summary, starts_in/60)

	if starts_in < 15*60 and not notified then
		notify upcoming, starts_in
		notified = true
	end
	sleep 60
end<commit_msg>Fix timezone errors from icalendar<commit_after>require 'icalendar'
require 'net/http'
require 'json'

$endpoint = ""

def notify(e, starts_in)
	events = URI('https://calendar.csail.mit.edu/event_calendar')
	lines = Net::HTTP.get(events).split("\n").select { |line| line.include? e.summary }
	# we'll get two hits, a div and the link
	href = URI.join(events, /href="([^"]*)"/.match(lines[1])[1])
	rinfo = Net::HTTP.get(href).scan(/<p>\s*<strong>(.*?):?<\/strong>(.*?)<\/p>/m)
	info = {}
	rinfo.each do |i|
		info[i[0]] = i[1]
			.gsub(/<br( \/)?>/, "\n")
			.strip
			.gsub(/\s+/, " ")
			.gsub(/\s,/, ",")
	end

	update = {
		:text => sprintf("The following talk starts in %d minutes in %s", starts_in/60, e.location),
		:channel => "#seminars",
		:username => "seminar-bot",
		:icon_emoji => ":ear:",
		:attachments => [
			{
				:author_name => info["Speaker"],
				:title => e.summary,
				:text => e.description,
				:fields => [
					{
						:title => "Room",
						:value => e.location,
						:short => true
					},
					{
						:title => "Time",
						:value => info["Time"],
						:short => true
					},
					{
						:title => "Host",
						:value => info["Host"],
						:short => true
					},
					{
						:title => "Refreshments",
						:value => info["Refreshments"],
						:short => true
					}
				]
			}
		]
	}
	if info["Relevant URL"] != "" then
		update[:attachments][:title_link] = info["Relevant URL"]
	end

	uri = URI($endpoint)
	res = Net::HTTP.post_form(uri, 'payload' => JSON.generate(update))
	puts res.body
end

begin
	$endpoint = File.open "endpoint.cfg", &:readline
rescue
	abort "endpoint.cfg not found: put the Slack Webhook URL in endpoint.cfg"
end

last = ""
notified = true
while true do
	events = URI('https://calendar.csail.mit.edu/event_calendar.ics')
	response = Net::HTTP.get(events)

	cal = Icalendar.parse(response)
	starts_in = -1
	while starts_in < 0 do
		upcoming = cal.first.events.shift
		if last != upcoming.summary then
			last = upcoming.summary
			notified = false
		end
		start = upcoming.dtstart.value.to_time - upcoming.dtstart.value.to_time.gmt_offset
		starts_in = start - Time.now
	end

	printf("next event: %s starts in %d minutes\n", upcoming.summary, starts_in/60)

	if starts_in < 15*60 and not notified then
		notify upcoming, starts_in
		notified = true
	end
	sleep 60
end
{'fraction_non_alphanumeric': 0.18733451015004413, 'fraction_numerical': 0.006619593998234775, 'mean_word_length': 3.0329181494661923, 'pattern_counts': {'":': 2, '<': 16, '<?xml version=': 0, '>': 57, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '990883', 'n_tokens_mistral': 1944, 'n_tokens_neox': 1641, 'n_words': 373}