Last active
July 31, 2018 11:36
-
-
Save ledell/3e41786c4f20f3e410b065ca7a8134dc to your computer and use it in GitHub Desktop.
Randomly select an attendee of a meetup to win a prize! (R-Ladies Budapest Example)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# library(devtools) | |
# devtools::install_github("rladies/meetupr") | |
library(meetupr) | |
# Log in to meetup.com, your key is here: https://secure.meetup.com/meetup_api/key/ | |
api_key <- "YOUR_API_KEY_HERE" | |
# `urlname` is a human-readable unique id for a meetup, e.g. https://www.meetup.com/R-Ladies-Budapest/ | |
urlname <- "R-Ladies-Budapest" | |
# Get the upcoming events (an ongoing/live event will still have "upcoming" status) | |
upcoming_events <- get_events(urlname = urlname, event_status = "upcoming", api_key = api_key) | |
print(upcoming_events$name[1]) | |
event_id <- upcoming_events$id[1] # next event (id) | |
# Get the RSVP list | |
rsvps <- get_event_rsvps(urlname = urlname, event_id = event_id, api_key = api_key) | |
# Subset to those who RSVP'd "yes" | |
attendees <- rsvps[rsvps$response == "yes", ] | |
head(attendees) | |
# Randomly choose an attendee | |
set.seed(1) # ask the audience for a seed! | |
winner_idx <- sample(1:nrow(rsvps), 1) | |
rsvps[winner_idx,] # print the winner! | |
# Optionally open their profile on meetup.com | |
winner_member_id <- rsvps[winner_idx, "member_id"] | |
browseURL(sprintf("https://www.meetup.com/%s/members/%s/", urlname, winner_member_id)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment