1
1
# frozen_string_literal: true
2
2
3
3
require "date"
4
- require "time"
5
4
6
5
class MeetupEvent
7
6
# Can be used like so:
8
- # \n:clock1: #{parse_duration(group['eventSearch ']['edges'][0]['node']['duration'])
7
+ # \n:clock1: #{parse_duration(group['unifiedEvents ']['edges'][0]['node']['duration'])
9
8
def self . parse_duration ( iso8601_duration )
10
9
match = iso8601_duration . match ( /PT((?<hours>\d +(?:\. \d +)?)H)?((?<minutes>\d +(?:\. \d +)?)M)?((?<seconds>\d +(?:\. \d +)?)S)?/ )
11
10
@@ -21,49 +20,19 @@ def self.parse_duration(iso8601_duration)
21
20
parts . join ( ", " ) + " long"
22
21
end
23
22
24
- def self . within_next_week? ( date_string )
25
- date = Date . parse ( date_string )
26
- today = Date . today
27
- date >= today && date <= ( today + 7 )
28
- end
29
-
30
- def self . within_next_day? ( date_string )
31
- date = Date . parse ( date_string )
32
- today = Date . today
33
- # today = Date.parse('2024-07-29T10:00-04:00')
34
- date == today
35
- end
36
-
37
- def self . within_next_hour? ( date_string )
38
- datetime = Time . parse ( date_string )
39
- now = Time . now
40
- # now = Time.parse('2024-07-29T18:00-04:00')
41
- one_hour_from_now = now + 3600
42
- datetime >= now && datetime <= one_hour_from_now
43
- end
44
-
45
- def self . format_slack ( group , announcement_type )
46
- return if group [ "eventSearch" ] [ "count" ] == 0
47
-
48
- date_string = group [ "eventSearch" ] [ "edges" ] [ 0 ] [ "node" ] [ "dateTime" ]
49
- if announcement_type == "weekly"
50
- return unless within_next_week? ( date_string )
51
- elsif announcement_type == "daily"
52
- return unless within_next_day? ( date_string )
53
- else
54
- return unless within_next_hour? ( date_string )
55
- end
23
+ def self . format_slack ( group )
24
+ return if group [ "unifiedEvents" ] [ "count" ] == 0
56
25
57
26
event_blocks = [ {
58
27
type : "section" ,
59
28
text : {
60
29
type : "mrkdwn" ,
61
- 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"
30
+ 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"
62
31
} ,
63
32
accessory : {
64
33
type : "image" ,
65
- image_url : group [ "eventSearch " ] [ "edges" ] [ 0 ] [ "node" ] [ "imageUrl" ] ,
66
- alt_text : "#{ group [ "name" ] } - #{ group [ "eventSearch " ] [ "edges" ] [ 0 ] [ "node" ] [ "title" ] } "
34
+ image_url : group [ "unifiedEvents " ] [ "edges" ] [ 0 ] [ "node" ] [ "imageUrl" ] ,
35
+ alt_text : "#{ group [ "name" ] } - #{ group [ "unifiedEvents " ] [ "edges" ] [ 0 ] [ "node" ] [ "title" ] } "
67
36
}
68
37
} ,
69
38
{
@@ -76,19 +45,19 @@ def self.format_slack(group, announcement_type)
76
45
text : ":dart: RSVP" ,
77
46
emoji : true
78
47
} ,
79
- url : group [ "eventSearch " ] [ "edges" ] [ 0 ] [ "node" ] [ "eventUrl" ]
48
+ url : group [ "unifiedEvents " ] [ "edges" ] [ 0 ] [ "node" ] [ "eventUrl" ]
80
49
}
81
50
]
82
51
} ,
83
52
]
84
53
85
54
if group [ "name" ] == "Tampa Devs"
86
- event_blocks [ 0 ] [ :text ] [ :text ] . prepend ( ":tampadevs: " )
55
+ event_blocks [ 0 ] [ :text ] [ :text ] = ":tampadevs:" + " " + event_blocks [ 0 ] [ :text ] [ :text ]
87
56
end
88
57
89
- if group [ "eventSearch " ] [ "edges" ] [ 0 ] [ "node" ] [ "venue" ]
90
- event_blocks [ 0 ] [ :text ] [ :text ] += if group [ "eventSearch " ] [ "edges" ] [ 0 ] [ "node" ] [ "venue" ] [ "name" ] != "Online event"
91
- "\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 ( ", " ) } >"
58
+ if group [ "unifiedEvents " ] [ "edges" ] [ 0 ] [ "node" ] [ "venue" ]
59
+ event_blocks [ 0 ] [ :text ] [ :text ] += if group [ "unifiedEvents " ] [ "edges" ] [ 0 ] [ "node" ] [ "venue" ] [ "name" ] != "Online event"
60
+ "\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 ( ", " ) } >"
92
61
else
93
62
"\n \n :computer: Online event"
94
63
end
0 commit comments