Last active
January 11, 2020 23:54
-
-
Save onhernandes/0435d36eb5763bfa11251537841282ce to your computer and use it in GitHub Desktop.
Know how your meetup.com group is growing through events!
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
# Know how your meetup.com group is growing through events! | |
# Get your API token here: https://secure.meetup.com/pt-BR/meetup_api/key/ | |
# You don't need to install nothing! It's 100% pure python | |
# python meetup-insights.py <group-name> <your api token> | |
from urllib import request,parse | |
from functools import reduce | |
import datetime | |
import sys | |
import json | |
if len(sys.argv) < 3: | |
print("You must pass your group name and your API key") | |
print("python meetup-insights.py <group-name> <api-key>") | |
sys.exit() | |
group = sys.argv[1] | |
key = sys.argv[2] | |
def make_url(path, additional): | |
additional["key"] = key | |
additional = parse.urlencode(additional) | |
return "https://api.meetup.com/%s?%s" % (path, additional) | |
def get_group(): | |
r = request.urlopen(make_url(group, {"only": "created,members,name,link"})) | |
return json.loads(r.read()) | |
def get_events(): | |
add = { | |
"only": "id,name,rsvp_limit,status,local_date,yes_rsvp_count", | |
"status": "past,upcoming" | |
} | |
r = request.urlopen(make_url("%s/events" % (group), add)) | |
return json.loads(r.read()) | |
def get_members(offset = 0): | |
add = { | |
"group_urlname": group, | |
"offset": offset, | |
"only": "joined" | |
} | |
r = request.urlopen(make_url("2/members", add)) | |
data = json.loads(r.read()) | |
results = data["results"] | |
if len(results) > 0: | |
results = results + get_members(offset + 1) | |
return results | |
def main(): | |
group_data = get_group() | |
members = get_members() | |
events = get_events() | |
convert = lambda t: datetime.datetime.strptime(t, "%Y-%m-%d") | |
deal_milliseconds = lambda t: datetime.datetime.utcfromtimestamp(0) + datetime.timedelta(milliseconds=t) | |
print("Group: %s\n" % (group_data["name"])) | |
for e in events: | |
local_date = convert(e["local_date"]) | |
date_compare = lambda m: deal_milliseconds(m["joined"]) < local_date | |
until_now = len(list(filter(date_compare, members))) | |
print("Event: %s" % (e["name"])) | |
print("Date: %s" % (e["local_date"])) | |
print("Total members until event date: %s\n" % (until_now)) | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment