-
Notifications
You must be signed in to change notification settings - Fork 4
/
dumprsvp.rb.orig
executable file
·70 lines (54 loc) · 1.91 KB
/
dumprsvp.rb.orig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
require 'uri'
require 'rest_client'
require 'yaml'
config = YAML.load(File.read(ENV['HOME'] + '/.getrsvpmeetup.yml'))
if ARGV.empty?
then $groupurlname = config['groupurlname']
else $groupurlname = ARGV[0]
end
$apikey = config['apikey']
$rpp = 200 # results per page
$datafile = File.expand_path(config['datafile'])
if File.file?($datafile)
then $memberhash = JSON.load(File.read($datafile))
else $memberhash = {}
end
RestClient.proxy = config['http_proxy'] if config['http_proxy']
RestClient.proxy = ENV['http_proxy'] if ENV['http_proxy']
response = RestClient.get 'https://api.meetup.com/2/events?key=' +
$apikey + '&group_urlname=' + $groupurlname + '&page=1&only=id'
if ARGV.size == 2
then $eventid = ARGV[1]
else $eventid = JSON.parse(response)["results"][0]["id"]
end
def get_page(offset)
page = RestClient.get "https://api.meetup.com/2/rsvps?key=" +
$apikey + "&sign=true&event_id=" + $eventid + "&page=" + $rpp.to_s +
"&offset=" + offset.to_s + "&rsvp=yes&order=name"
return page
end
def get_attendeecount
response = get_page(0)
attendeecount = JSON.parse(response)["meta"]["total_count"]
return attendeecount
end
pagestoget = get_attendeecount / $rpp + 1
$attendees = []
(0..pagestoget).each do |i|
response = get_page(i)
$attendees = $attendees + JSON.parse(response)["results"]
end
$attendeehash = {}
$attendees.each { |x|
k = x['member']['member_id'].to_s
if $memberhash.has_key?(k) and $memberhash[k]['Status'] != 'Suspect'
then
$attendeehash[k] = { 'MeetupName' => x['member']['name'].to_s, 'Member_ID' => x['member']['member_id'].to_s, 'RealName' => $memberhash[k]['RealName'].to_s }
$attendeehash[k]['LastName'] = $attendeehash[k]['RealName'].split.last.to_str
$attendeehash[k]['FirstName'] = $attendeehash[k]['RealName'].gsub($attendeehash[k]['LastName'],'').rstrip
end
}
puts JSON.pretty_generate($attendeehash)