@@ -71,6 +71,13 @@ def headers(context)
7171 createdAt
7272 eventType
7373 isOnline
74+ group {
75+ id
76+ name
77+ country
78+ state
79+ city
80+ }
7481 }
7582 }
7683 }
@@ -89,26 +96,6 @@ class MeetupGroup < FrozenRecord::Base
8996 scope :meetupdotcom , -> { where ( service : "meetupdotcom" ) }
9097 scope :luma , -> { where ( service : "luma" ) }
9198
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-
11299 def upcoming_events
113100 result = MeetupClient ::Client . query ( EventsQuery , variables : { groupId : id } )
114101
@@ -142,41 +129,55 @@ def existing_event_ids
142129 end
143130
144131 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-
161132 timezone = TZInfo ::Timezone . get ( event . timezone ) . now . strftime ( "%Z" )
162133
163134 <<~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 ) } "
166137 date: #{ Date . parse ( event . dateTime ) . iso8601 }
167138 start_time: "#{ Time . parse ( event . dateTime ) . strftime ( "%H:%M:%S" ) } #{ timezone } "
168139 end_time: "#{ Time . parse ( event . endTime ) . strftime ( "%H:%M:%S" ) } #{ timezone } "
169140 url: "#{ event . eventUrl } "
170141 YAML
171142 end
172143
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
176149
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 |
177152 File . write ( "./_data/meetups.yml" , openstruct_to_yaml ( event ) , mode : "a+" )
178153 end
179154 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
180181end
181182
182183class Meetup < FrozenRecord ::Base
0 commit comments