Last active
October 13, 2018 17:00
-
-
Save Jiwan/30e22dc90c55fc29e3c8e8a1873390f7 to your computer and use it in GitHub Desktop.
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
import argparse | |
import datetime | |
import unicodecsv as csv | |
import meetup.api | |
import os.path | |
columns = ['name', 'real_name', 'kingster', 'id', 'rsvp', 'rsvp_date', 'joined_group_date', 'title', 'host', 'url', 'new_entry'] | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description='Get the attendee names for a meetup.') | |
parser.add_argument('--api-key', required=True) | |
parser.add_argument('--meetup', required=True) | |
parser.add_argument('--event-id', required=True) | |
parser.add_argument('--csv-file', required=True) | |
args = parser.parse_args() | |
attendees_list = [] | |
if os.path.exists(args.csv_file): | |
with open(args.csv_file, 'rb') as csvfile: | |
reader = csv.DictReader(csvfile) | |
for row in reader: | |
attendees_list.append(row) | |
attendees = {} | |
for attendee in attendees_list: | |
id = str(attendee.pop('id')) | |
attendees[id] = attendee | |
client = meetup.api.Client(args.api_key) | |
rsvps = client.GetRsvps(event_id=args.event_id, urlname=args.meetup) | |
for rsvp in rsvps.results: | |
id = str(rsvp['member']['member_id']) | |
if id in attendees.keys(): | |
attendees[id]['new_entry'] = False | |
else: | |
attendees[id] = {} | |
attendees[id]['new_entry'] = True | |
attendees[id]['name'] = rsvp['member']['name'] | |
attendees[id]['rsvp'] = rsvp['response'] | |
attendees[id]['url'] = 'https://www.meetup.com/swedencpp/members/' + str(id) | |
attendees[id]['rsvp_date'] = datetime.datetime.fromtimestamp((rsvp['created'] / 1000)).strftime('%Y-%m-%d %H:%M:%S') | |
attendees_list = [] | |
for id, data in attendees.items(): | |
data['id'] = id | |
attendees_list.append(data) | |
attendees_list = sorted(attendees_list, key=lambda x: x['name'].lower()) | |
with open(args.csv_file, 'w') as csvfile: | |
writer = csv.DictWriter(csvfile, fieldnames=columns) | |
writer.writeheader() | |
for attendee in attendees_list: | |
writer.writerow(attendee) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment