def rsvp_events(sess, token, group): """ Used to RSVP the events of a particular group Parameters: sess (requests.Session object): A Session object of the logged in session group (Group object) : A object of Group class, denoting selected group. Returns: None Writes: logs the RSVP-ed events into a 'rsvped_events.json' file. """ url = get_upcoming_events_url(group) rsvped_events_string = get_rsvped_events_string() res = sess.get(url) soup = BeautifulSoup(res.text, 'html.parser') all_events = soup.find_all('a', {'id': 'attendButton'}) rsvped_events = [] for event in all_events: sess.headers = base_headers.RSVP_GET id = event.get('href').split('/')[-2] rsvp_endpoint = urls.BASE_URL + \ event.get('href')+'action=rsvp&response=yes' if id in rsvped_events_string: continue if not args.dry_run: params = ( ('action', 'rsvp'), ('response', 'yes'), ) res = sess.get(urls.BASE_URL + event.get('href'), params=params) sess.headers = base_headers.RSVP_POST sess.headers['x-mwp-csrf'] = sess.cookies['x-mwp-csrf-header'] sess.headers['referer'] = rsvp_endpoint query = '(endpoint:' + group.group_url + "/events/" + id + "/rsvps" + ',meta:(method:post),' + 'params:(eventId:' + id + \ ',fields:rsvp_counts,' + 'response:yes,' + 'urlname:' + group.group_url + \ ')' + ',ref:rsvpAction' + "_" + group.group_url + '_' + id + ')' data = { 'queries': query } res = sess.post( 'https://www.meetup.com/mu_api/urlname/events/eventId', data=data) if res.status_code == 200: rsvp_event = Event(group.group_name, id, True) rsvped_events.append(rsvp_event) old_rsvped_events = [Event.fromJson(x) for x in json.loads(rsvped_events_string)] rsvped_events += old_rsvped_events jsonStr = json.dumps([x.__dict__ for x in rsvped_events]) with open('rsvped_events.json', "w") as f: f.seek(0) f.write(jsonStr) f.truncate()
res = session.post( 'https://www.meetup.com/mu_api/urlname/events/eventId', data=data) if res.status_code == 200: rsvp_event = Event(group.group_name, id, True) rsvped_events.append(rsvp_event) return rsvped_events #used to write RSVPed events into 'rsvped_events.json' file. def rsvp_events(session, token, group): rsvped_events_string = get_rsvped_events_string() rsvped_events = get_event_rsvped(rsvped_events_string, session, group) old_rsvped_events = [Event.fromJson(x) for x in json.loads(rsvped_events_string)] rsvped_events += old_rsvped_events rsvpList = json.dumps([x.__dict__ for x in rsvped_events]) with open('rsvped_events.json', "w") as f: f.seek(0) f.write(rsvpList) f.truncate() #driver function def main(): selected_groups = get_selected_groups() logged_in_session, token = authentication.signin(verbose=False)