@@ -71,6 +71,13 @@ def headers(context)
71
71
createdAt
72
72
eventType
73
73
isOnline
74
+ group {
75
+ id
76
+ name
77
+ country
78
+ state
79
+ city
80
+ }
74
81
}
75
82
}
76
83
}
@@ -89,26 +96,6 @@ class MeetupGroup < FrozenRecord::Base
89
96
scope :meetupdotcom , -> { where ( service : "meetupdotcom" ) }
90
97
scope :luma , -> { where ( service : "luma" ) }
91
98
92
- def location
93
- unless @upcoming_events_result
94
- upcoming_events
95
- end
96
-
97
- group = @upcoming_events_result . original_hash . dig ( "data" , "groupByUrlname" )
98
-
99
- city = group . dig ( "city" )
100
- state = group . dig ( "state" )
101
- country = group . dig ( "country" )
102
-
103
- country = ISO3166 ::Country . new ( country )
104
-
105
- if country . alpha2 == "US"
106
- "#{ city } , #{ state . upcase } "
107
- else
108
- "#{ city } , #{ country &.iso_short_name } "
109
- end
110
- end
111
-
112
99
def upcoming_events
113
100
result = MeetupClient ::Client . query ( EventsQuery , variables : { groupId : id } )
114
101
@@ -142,41 +129,55 @@ def existing_event_ids
142
129
end
143
130
144
131
def openstruct_to_yaml ( event )
145
- city = event . venue . dig ( "city" )
146
- state = event . venue . dig ( "state" )
147
- country = event . venue . dig ( "country" )
148
-
149
- country = ISO3166 ::Country . new ( country )
150
-
151
- if event . isOnline
152
- meetup_location = "Online"
153
- elsif country . alpha2 == "US"
154
- meetup_location = "#{ city } , #{ state . upcase } "
155
- elsif country
156
- meetup_location = "#{ city } , #{ country &.iso_short_name } "
157
- else
158
- meetup_location = location
159
- end
160
-
161
132
timezone = TZInfo ::Timezone . get ( event . timezone ) . now . strftime ( "%Z" )
162
133
163
134
<<~YAML
164
- - name: "#{ name } - #{ event . title . gsub ( name , "" ) . squeeze ( " " ) . strip } "
165
- location: "#{ meetup_location } "
135
+ - name: "#{ event_title ( event ) } "
136
+ location: "#{ event_to_location ( event ) } "
166
137
date: #{ Date . parse ( event . dateTime ) . iso8601 }
167
138
start_time: "#{ Time . parse ( event . dateTime ) . strftime ( "%H:%M:%S" ) } #{ timezone } "
168
139
end_time: "#{ Time . parse ( event . endTime ) . strftime ( "%H:%M:%S" ) } #{ timezone } "
169
140
url: "#{ event . eventUrl } "
170
141
YAML
171
142
end
172
143
173
- def write_new_meetups!
174
- new_events . each do |event |
175
- next unless Date . parse ( event . dateTime ) . between? ( Date . today - 1 , Date . today + 90 )
144
+ def openstruct_to_md ( event )
145
+ <<~MD
146
+ | [#{ event_title ( event ) } ](#{ event . eventUrl } ) | #{ Date . parse ( event . dateTime ) . strftime ( "%b %d, %Y" ) } | [#{ name } ](https://www.meetup.com/#{ id } ) |
147
+ MD
148
+ end
176
149
150
+ def write_new_meetups!
151
+ new_events . sort_by ( &:dateTime ) . select { |event | Date . parse ( event . dateTime ) . between? ( Date . today - 1 , Date . today + 90 ) } . each do |event |
177
152
File . write ( "./_data/meetups.yml" , openstruct_to_yaml ( event ) , mode : "a+" )
178
153
end
179
154
end
155
+
156
+ private
157
+
158
+ def event_title ( event )
159
+ "#{ name } - #{ event . title . gsub ( name , "" ) . squeeze ( " " ) . strip } "
160
+ end
161
+
162
+ def event_to_location ( event )
163
+ city = event . venue . dig ( "city" ) || event . group . dig ( "city" )
164
+ state = event . venue . dig ( "state" ) || event . group . dig ( "state" )
165
+ country_raw = event . venue . dig ( "country" ) || event . group . dig ( "country" )
166
+
167
+ country = ISO3166 ::Country . new ( country_raw )
168
+
169
+ if event . isOnline
170
+ "Online"
171
+ elsif country . alpha2 == "US"
172
+ "#{ city } , #{ state . upcase } "
173
+ elsif country
174
+ "#{ city } , #{ country &.iso_short_name } "
175
+ elsif city
176
+ "#{ city } , #{ state } , #{ country_raw . upcase } "
177
+ else
178
+ "Unknown"
179
+ end
180
+ end
180
181
end
181
182
182
183
class Meetup < FrozenRecord ::Base
0 commit comments