Add meetup.rb script

Add meetup.rb script

This script is intended to be run from a local terminal, it is not run as part of the plugin

diff --git a/scripts/meetup.rb b/scripts/meetup.rb
new file mode 100644
index 0000000..8ff063d
--- /dev/null
+++ b/scripts/meetup.rb
@@ -0,0 +1,72 @@
+#!/usr/bin/env ruby
+
+=begin
+Script to extract dates from all posts within topic
+Used to identify conflicts when planning an event
+One date per line
+Use <skip> at the start of the post if not including dates
+Dates should use standard 3 letter month abbreviation
+
+Example post:
+
+Sep 13 - Sep 20
+Oct 16
+Oct 25 - Oct 27
+=end
+
+fail "API_KEY required"       unless @key = ENV["API_KEY"]
+fail "API_USERNAME required"  unless @username = ENV["API_USERNAME"]
+fail "URL required"           unless @url = ENV["URL"]
+
+require "set"
+require "date"
+require "json"
+
+def posts(page)
+  JSON.parse(`curl -s "#{@url}.json?page=#{page}&include_raw=true" -H "Api-Username: #{@username}" -H "Api-Key: #{@key}"`)
+end
+
+def find_bad_dates(raw)
+  dates = []
+  raw.strip.split("\n").each { |line|
+    a, b = line.scan(/\w+ \d+/).map { |d| Date.parse(d) }
+    b ||= a
+    (a..b).each { |d| dates << Date.parse(d.to_s) }
+  }
+  dates
+end
+
+map = {}
+
+
+(1..).each do |page|
+  json = posts(page)
+  break if json.dig("post_stream", "posts").nil?
+  json.dig("post_stream", "posts").each do |post|
+    next if post["post_number"] == 1
+    next if post["raw"].start_with?("<skip>")
+    bad_dates = map[post["username"]] ||= []
+    bad_dates.concat(find_bad_dates(post["raw"]))
+  end
+end
+
+puts "#{map.keys.length} users found!"
+
+start_date = Date.parse("29-08-2020")
+weeks = 9.times.map { [start_date += 1, start_date += 6] }
+
+weeks.each do |start, finish|
+  problem_users = []
+
+  map.each do |user, dates|
+    found = dates.select { |date| date <= finish && date >= start }
+    problem_users << [user, found] if found.size > 0
+  end
+
+  problem_text = problem_users.map do |name, dates|
+    days = dates.map { |date| date.strftime('%a')[0..1] }.join(",")
+    "#{name} (#{days})"
+  end.join(" ")
+
+  puts "#{start} #{finish} : #{problem_users.count} issues. #{problem_text}"
+end

GitHub sha: 21852034

1 Like