def get_meeting_participants(): meetings = defaultdict(list) participants = MeetingParticipant.query().fetch() for participant in participants: try: email = participant.user.get().email meeting = participant.meeting meetings[meeting].append(email) except AttributeError: pass metrics = [] for meeting_key in meetings.keys(): meeting_spec = meeting_key.get().meeting_spec.get() meeting_title = meeting_spec.meeting_subscription.get().title participants = meetings[meeting_key] for participant in participants: metrics.append({ 'participant': participant, 'meeting': meeting_key.urlsafe(), 'meeting_title': meeting_title, 'date': meeting_spec.datetime.isoformat(), 'time': get_meeting_datetime(meeting_spec).strftime('%I:%M%p'), }) return metrics
def get_meeting_participants(): meetings = defaultdict(list) participants = MeetingParticipant.query.all() for participant in participants: try: email = participant.user.email meeting_id = participant.meeting_id meetings[meeting_id].append(email) except AttributeError: pass metrics = [] for meeting_id in meetings.keys(): meeting_spec = Meeting.query.filter( Meeting.id == meeting_id).one().meeting_spec meeting_title = meeting_spec.meeting_subscription.title participants = meetings[meeting_id] for participant in participants: metrics.append({ 'participant': participant, 'meeting': meeting_id, 'meeting_title': meeting_title, 'date': meeting_spec.datetime.isoformat(), 'time': get_meeting_datetime(meeting_spec).strftime('%I:%M%p'), }) return metrics
def send_batch_weekly_opt_in_email(meeting_spec): """Sends an email for the week asking if members want a meeting""" create_url = 'https://yelp-beans.appspot.com/meeting_request/{}'.format( meeting_spec.key.urlsafe()) logging.info('created url ' + create_url) users = get_users_from_spec(meeting_spec) users = [user for user in users if user] logging.info(len(users)) logging.info(meeting_spec) meeting_datetime = get_meeting_datetime(meeting_spec) subscription = meeting_spec.meeting_subscription.get() logging.info(meeting_datetime.strftime('%I:%M %p %Z')) for user in users: if not user.terminated: logging.info(user) logging.info(meeting_datetime) send_single_email( user.email, "Want a yelp-beans meeting this week?", "weekly_opt_in_email.html", { 'first_name': user.first_name, 'office': subscription.office, 'location': subscription.location, 'meeting_day': meeting_datetime.strftime('%A'), 'meeting_time': meeting_datetime.strftime('%I:%M %p %Z'), 'meeting_url': create_url, 'link_to_change_pref': 'https://yelp-beans.appspot.com/' }) logging.info('sent email') else: logging.info(user) logging.info('terminated')
def send_match_email(user, participants, meeting_spec): """ Sends an email to one of the matches for the week user - user receiving the email participants - other people in the meeting meeting_spec - meeting specification """ meeting_datetime = get_meeting_datetime(meeting_spec) meeting_datetime_end = meeting_datetime + datetime.timedelta(minutes=30) subscription = meeting_spec.meeting_subscription.get() send_single_email( user.email, 'Yelp Beans Meeting', 'match_email.html', { 'user': user, 'participants': participants, 'location': subscription.office + " " + subscription.location, 'meeting_title': subscription.title, 'meeting_start_day': meeting_datetime.strftime('%A'), 'meeting_start_date': meeting_datetime.strftime('%m/%d/%Y'), 'meeting_start_time': meeting_datetime.strftime('%I:%M %p %Z'), 'meeting_end_time': meeting_datetime_end.strftime('%I:%M %p %Z'), 'calendar_invite_url': create_google_calendar_invitation_link( participants, subscription.title, subscription.office, subscription.location, meeting_datetime, meeting_datetime_end), })
def test_get_specs_from_subscription_pdt(minimal_database): preference = SubscriptionDateTime( datetime=datetime(2017, 1, 20, 13, 0)).put() subscription = MeetingSubscription(timezone='America/Los_Angeles', datetime=[preference]).put() _, specs = get_specs_from_subscription(subscription.get()) assert get_meeting_datetime(specs[0]).hour == 13
def test_get_specs_from_subscription_pdt(session): preference = SubscriptionDateTime(datetime=datetime(2017, 1, 20, 13, 0)) session.add(preference) subscription = MeetingSubscription(timezone='America/Los_Angeles', datetime=[preference]) session.add(subscription) session.commit() _, specs = get_specs_from_subscription(subscription) assert get_meeting_datetime(specs[0]).hour == 13
def match_employees(): specs = get_specs_for_current_week() for spec in specs: logging.info('Spec Datetime: ') logging.info(get_meeting_datetime(spec).strftime("%Y-%m-%d %H:%M")) users = [ request.user.get() for request in MeetingRequest.query( MeetingRequest.meeting_spec == spec.key).fetch() ] logging.info('Users: ') logging.info([user.get_username() for user in users]) matches, unmatched = generate_meetings(users, spec) save_meetings(matches, spec) send_batch_unmatched_email(unmatched) send_batch_meeting_confirmation_email(matches, spec) return "OK"
def get_meeting_participants(): # We are looking at all meetings and every subscription is likely to have a # meeting, so we should need all subscription information. We could load this # through a db join, but that makes the query more expensive and returns a lot # duplicate data since there should always be more meetings then subscriptions. # Doing the join in python allows us to get the data only once and shouldn't # require us getting more data than needed subscription_id_to_subscription = { meet_sub.id: meet_sub for meet_sub in MeetingSubscription.query.all() } participants = MeetingParticipant.query.options( joinedload(MeetingParticipant.user), joinedload(MeetingParticipant.meeting).joinedload( Meeting.meeting_spec), ).all() metrics = [] for participant in participants: meeting_spec = participant.meeting.meeting_spec meeting_subscription = subscription_id_to_subscription[ meeting_spec.meeting_subscription_id] meeting_title = meeting_subscription.title metrics.append({ 'participant': participant.user.email, 'meeting': participant.meeting.id, 'meeting_title': meeting_title, 'date': meeting_spec.datetime.isoformat(), 'time': get_meeting_datetime( meeting_spec, meeting_subscription.timezone).strftime('%I:%M%p'), }) return metrics
def test_get_meeting_datetime(database, subscription): assert get_meeting_datetime(database.specs[0]).hour == 15