Skip to content

Instantly share code, notes, and snippets.

@botanicus
Created June 4, 2015 07:04
Show Gist options
  • Save botanicus/685e775758326917f1f8 to your computer and use it in GitHub Desktop.
Save botanicus/685e775758326917f1f8 to your computer and use it in GitHub Desktop.
What's going on in business and tech on Meetup.com?
#!/usr/bin/env ruby
# This doesn't click 'More', so it's not the same as
# using the Meetup API, but fuck that, it's simple and
# works just fine.
require 'open-uri'
require 'nokogiri'
require 'pry'
URLS = {
'All' => 'http://www.meetup.com/find/events/?allMeetups=true&radius=50&userFreeform=London%2C+Greater+London%2C+England%2C+United+Kingdom&mcId=c1012717&mcName=London%2C+England%2C+GB&eventFilter=all',
'Business' => 'http://www.meetup.com/find/events/career-business/?allMeetups=false&radius=50&userFreeform=London%2C+Greater+London%2C+England%2C+United+Kingdom&mcId=c1012717&mcName=London%2C+England%2C+GB&eventFilter=all',
'Tech' => 'http://www.meetup.com/find/events/tech/?allMeetups=false&radius=50&userFreeform=London%2C+Greater+London%2C+England%2C+United+Kingdom&mcId=c1012717&mcName=London%2C+England%2C+GB&eventFilter=all',
}
class Event
def initialize(li)
@li = li
end
def attendee_count
@li.css('.attendee-count').inner_html.scan(/\d+/).first.to_i
end
def start_time
@li.css('time[itemprop=startDate]').attribute('datetime')
end
def to_s
desc = @li.css('span[itemprop=summary]').inner_text
url = @li.css('a[itemprop=url]').attribute('href')
attendees = @li.css('.attendee-count').inner_html.scan(/\d+/).first
"#{attendees} | #{start_time} | #{desc} – #{url}"
end
end
URLS.each do |name, url|
puts "\n=== #{name} ==="
open(url) do |stream|
doc = Nokogiri::HTML(stream.read)
events = doc.css('.event-listing').map do |li|
Event.new(li)
end
puts events
.select { |event| event.attendee_count > 20 }
.sort_by { |event| event.attendee_count }.reverse
end
end
__END__
<li class="event-listing line-gutters clearfix doc-padding " data-year="2015" data-month="5" data-day="18" itemscope itemtype="http://data-vocabulary.org/Event">
<div class="unit size1of7">
<a href="http://www.meetup.com/45-Not-grumpy-old-Londoners-Love-life-travel-and-culture/events/220945751/" class="list-time unlink omnCamp omngj_sj7eall omnrv_fe1all">
<time itemprop="startDate" datetime="2015-05-18T15:45:00+01:00">10:45<span class="period">AM</span></time>
</a>
</div>
<div class="unit size4of7">
<div itemprop="location" itemscope itemtype="http://data-vocabulary.org/Organization">
<a href="http://www.meetup.com/45-Not-grumpy-old-Londoners-Love-life-travel-and-culture/" class="chapter-name unlink omnCamp omngj_sj7eall omnrv_fe1all" itemprop="url">
<span itemprop="name">45+ Not grumpy old Londoners! Love life, travel and culture</span>
</a>
</div>
<a href="http://www.meetup.com/45-Not-grumpy-old-Londoners-Love-life-travel-and-culture/events/220945751/" class="big event-title bold unlink-dark wrapNice omnCamp omngj_sj7eall omnrv_fe1all" itemprop="url">
<span itemprop="summary">Visit FREEMASONS LODGE and interesting afternoon</span>
</a>
<div class="list-rsvpers clearfix">
<div class="attendee-count">
31
Friends
going
</div>
</div>
</div>
<div class="unit size2of7 friend-container">
</div>
</li>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment