Skip to content

Commit

Permalink
Merge branch 'master' into add-daily-reminders
Browse files Browse the repository at this point in the history
  • Loading branch information
ebanner committed Sep 12, 2024
2 parents d551e64 + 7de4d66 commit 0e89ba2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 56 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PLATFORMS
x86_64-linux
arm64-darwin-21
arm64-darwin-22
arm64-darwin-23
x86_64-linux

DEPENDENCIES
Expand Down
53 changes: 11 additions & 42 deletions event.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# frozen_string_literal: true

require "date"
require "time"

class MeetupEvent
# Can be used like so:
# \n:clock1: #{parse_duration(group['eventSearch']['edges'][0]['node']['duration'])
# \n:clock1: #{parse_duration(group['unifiedEvents']['edges'][0]['node']['duration'])
def self.parse_duration(iso8601_duration)
match = iso8601_duration.match(/PT((?<hours>\d+(?:\.\d+)?)H)?((?<minutes>\d+(?:\.\d+)?)M)?((?<seconds>\d+(?:\.\d+)?)S)?/)

Expand All @@ -21,49 +20,19 @@ def self.parse_duration(iso8601_duration)
parts.join(", ") + " long"
end

def self.within_next_week?(date_string)
date = Date.parse(date_string)
today = Date.today
date >= today && date <= (today + 7)
end

def self.within_next_day?(date_string)
date = Date.parse(date_string)
today = Date.today
# today = Date.parse('2024-07-29T10:00-04:00')
date == today
end

def self.within_next_hour?(date_string)
datetime = Time.parse(date_string)
now = Time.now
# now = Time.parse('2024-07-29T18:00-04:00')
one_hour_from_now = now + 3600
datetime >= now && datetime <= one_hour_from_now
end

def self.format_slack(group, announcement_type)
return if group["eventSearch"]["count"] == 0

date_string = group["eventSearch"]["edges"][0]["node"]["dateTime"]
if announcement_type == "weekly"
return unless within_next_week?(date_string)
elsif announcement_type == "daily"
return unless within_next_day?(date_string)
else
return unless within_next_hour?(date_string)
end
def self.format_slack(group)
return if group["unifiedEvents"]["count"] == 0

event_blocks = [{
type: "section",
text: {
type: "mrkdwn",
text: "*#{group["name"]}* - *#{group["eventSearch"]["edges"][0]["node"]["title"]}*\n:calendar: #{DateTime.parse(group["eventSearch"]["edges"][0]["node"]["dateTime"]).strftime("%A, %d %B %Y, %I:%M %p")}\n:busts_in_silhouette: #{group["eventSearch"]["edges"][0]["node"]["going"]} going"
text: "*#{group["name"]}* - *#{group["unifiedEvents"]["edges"][0]["node"]["title"]}*\n:calendar: #{DateTime.parse(group["unifiedEvents"]["edges"][0]["node"]["dateTime"]).strftime("%A, %d %B %Y, %I:%M %p")}\n:busts_in_silhouette: #{group["unifiedEvents"]["edges"][0]["node"]["going"]} going"
},
accessory: {
type: "image",
image_url: group["eventSearch"]["edges"][0]["node"]["imageUrl"],
alt_text: "#{group["name"]} - #{group["eventSearch"]["edges"][0]["node"]["title"]}"
image_url: group["unifiedEvents"]["edges"][0]["node"]["imageUrl"],
alt_text: "#{group["name"]} - #{group["unifiedEvents"]["edges"][0]["node"]["title"]}"
}
},
{
Expand All @@ -76,19 +45,19 @@ def self.format_slack(group, announcement_type)
text: ":dart: RSVP",
emoji: true
},
url: group["eventSearch"]["edges"][0]["node"]["eventUrl"]
url: group["unifiedEvents"]["edges"][0]["node"]["eventUrl"]
}
]
},
]

if group["name"] == "Tampa Devs"
event_blocks[0][:text][:text].prepend(":tampadevs: ")
event_blocks[0][:text][:text] = ":tampadevs:" + " " + event_blocks[0][:text][:text]
end

if group["eventSearch"]["edges"][0]["node"]["venue"]
event_blocks[0][:text][:text] += if group["eventSearch"]["edges"][0]["node"]["venue"]["name"] != "Online event"
"\n\n:round_pushpin: <https://www.google.com/maps/dir/?api=1&destination=#{group["eventSearch"]["edges"][0]["node"]["venue"].map { |k, v| "#{k}=#{URI.encode_www_form_component(v)}" }.join("&")}|#{group["eventSearch"]["edges"][0]["node"]["venue"].values.join(", ")}>"
if group["unifiedEvents"]["edges"][0]["node"]["venue"]
event_blocks[0][:text][:text] += if group["unifiedEvents"]["edges"][0]["node"]["venue"]["name"] != "Online event"
"\n\n:round_pushpin: <https://www.google.com/maps/dir/?api=1&destination=#{group["unifiedEvents"]["edges"][0]["node"]["venue"].map { |k, v| "#{k}=#{URI.encode_www_form_component(v)}" }.join("&")}|#{group["unifiedEvents"]["edges"][0]["node"]["venue"].values.join(", ")}>"
else
"\n\n:computer: Online event"
end
Expand Down
22 changes: 13 additions & 9 deletions main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,32 @@ def initialize

def fetch
argument = ARGV[0]
if argument == '--weekly'
announcement_type = 'weekly'
elsif argument == '--daily'
if argument == '--daily'
announcement_type = 'daily'
else
events_url = 'https://events.api.tampa.dev?within_hours=24'
elsif argument == '--hourly'
announcement_type = 'hourly'
events_url = 'https://events.api.tampa.dev?within_hours=1'
else
announcement_type = 'weekly'
events_url = 'https://events.api.tampa.dev?within_days=7'
end

groups = JSON.parse(Net::HTTP.get(URI("https://events.api.tampa.dev/")))
groups = JSON.parse(Net::HTTP.get(URI(events_url)))

sorted_events = []
formatted_events = []

groups.each do |group|
sorted_events << group[1] unless group[1]["eventSearch"]["count"] == 0
sorted_events << group[1] unless group[1]["unifiedEvents"]["count"] == 0 || group[1]["unifiedEvents"]["edges"].empty?
end

sorted_events.sort! { |a, b| DateTime.parse(a["eventSearch"]["edges"][0]["node"]["dateTime"]) <=> DateTime.parse(b["eventSearch"]["edges"][0]["node"]["dateTime"]) }
sorted_events.sort! do |a, b|
DateTime.parse(a["unifiedEvents"]["edges"][0]["node"]["dateTime"]) <=> DateTime.parse(b["unifiedEvents"]["edges"][0]["node"]["dateTime"])
end

sorted_events.each do |group|
event = MeetupEvent.format_slack(group, announcement_type)
event = MeetupEvent.format_slack(group)
formatted_events << event unless event.nil?
end

Expand All @@ -54,4 +59,3 @@ def fetch

syn = EventSyndicator.new
syn.fetch

20 changes: 15 additions & 5 deletions slack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ def self.payload(events)
value: "see_all_meetups",
url: "https://tampa.dev?utm_source=td_slack_syndication&utm_campaign=organic"
},
{
type: "button",
text: {
type: "plain_text",
text: ":calendar: Event Calendar",
emoji: true
},
value: "newsletter_tampa_dev",
url: "https://go.tampa.dev/calendar?utm_source=td_slack_syndication&utm_campaign=organic"
},
{
type: "button",
text: {
Expand All @@ -80,7 +90,7 @@ def self.payload(events)
type: "button",
text: {
type: "plain_text",
text: ":briefcase: Hire a Developer",
text: ":briefcase: Local Tech Jobs",
emoji: true
},
value: "events_api",
Expand All @@ -90,11 +100,11 @@ def self.payload(events)
type: "button",
text: {
type: "plain_text",
text: ":newspaper: Tampa Tech News",
text: ":newspaper: Newsletter",
emoji: true
},
value: "news_tampa_dev",
url: "https://news.tampa.dev?utm_source=td_slack_syndication&utm_campaign=organic"
value: "newsletter_tampa_dev",
url: "https://newsletter.tampa.dev?utm_source=td_slack_syndication&utm_campaign=organic"
}
]
}
Expand All @@ -117,7 +127,7 @@ def self.message_json
def self.post
return if @payload.length == 0

targets = [ENV["TD_SLACK_WEBHOOK"]]
targets = [ENV["TD_SLACK_WEBHOOK"], ENV["TBT_SLACK_WEBHOOK"], ENV["TBUX_SLACK_WEBHOOK"]]

targets.each do |t|
uri = URI.parse(t)
Expand Down

0 comments on commit 0e89ba2

Please sign in to comment.