Beispiel #1
0
 def resend_maybe_invitations(self):
     for inv in self.invitations.filter(state='MAYBE'):
         # TODO: Figure out rabbitmq
         send_copilot_sms.apply_async((inv.text, inv.sent_to.phone_number))
         # copilot_send_sms(inv.text, inv.sent_to.phone_number)
         # send_sms(text, inv.sent_to.phone_number)
         inv.sent_count += 1
         inv.save()
Beispiel #2
0
def send_participant_invitations_for_event(event):
    # to avoid circular imports
    from base.models import Invitation, Crew, UserProfile

    crew = None
    try:
        crew = event.crew_sent_to
    except Exception:
        pass

    # hardcode for now
    # for testing
    if not crew:
        alec = UserProfile.objects.get(phone_number='')
        if event.organizer == alec:
            crew = Crew.objects.get(name='Alec Test Crew')
        else:
            crew = Crew.objects.get(name='Cornell Club Bball')

    send_to_qs = crew.userprofiles.filter(opted_out=False).exclude(
        id=event.organizer.id)

    number_of_players_to_send_to = event.number_of_players if event.number_of_players else -1
    for up in send_to_qs:
        text = 'Hi' + ((' ' + str(up.name)) if up.name else '') + '! You\'ve been invited to join a GoodRun event' + \
            ((' by ' + str(event.organizer.name)) if event.organizer.name else '.') + '\n\n'
        text += 'The event details:\n\n'
        text += event.get_pretty_event_details() + '\n\n'
        text += 'Please respond if you will be attending the run.\n'
        text += 'Options: \'yes\', \'no\', or \'maybe\' (maybe means we\'ll text you before the event if it\'s not full). \n\n'
        text += '(to opt out reply /optout)'
        if abs(number_of_players_to_send_to) < 1:
            break
        # handle call back somehow, set invitation to error if failed
        Invitation.objects.create(event=event, sent_to=up, text=text)
        # TODO: Figure out RabbitMQ in production
        send_copilot_sms.apply_async((text, up.phone_number))
        # copilot_send_sms(text, up.phone_number)
        # send_sms(text, up.phone_number)
        number_of_players_to_send_to -= 1
    event.invitations_have_sent = True
    event.save()
Beispiel #3
0
 def resend_to_non_responses(self):
     for inv in self.invitations.filter(state='SENT'):
         send_copilot_sms.apply_async((inv.text, inv.sent_to.phone_number))
         inv.sent_count += 1
         inv.save()
Beispiel #4
0
 def remind_accepted_invitations(self):
     text = 'This is a reminder for your upcoming GoodRun event. Details are below: \n\n'
     text += self.get_pretty_event_details()
     for inv in self.invitations.filter(state='ACCEPTED'):
         # TODO: Figure out rabbitmq
         send_copilot_sms.apply_async((text, inv.sent_to.phone_number))
Beispiel #5
0
        return True
    # TODO: handle error here, text one of us the error?
    except Exception:
        return False


def copilot_send_sms(outbound_text, to_phone_number):
    m_id = ''

    try:
        client = Client(account_sid, auth_token)
        message = client.messages.create(to=to_phone_number,
                                         from_=m_id,
                                         body=outbound_text)
        return message
    except Exception:
        return False


outbound_text = 'copilot test'
to_phone_number = ''
# can't send to google # ?
copilot_send_sms(outbound_text, to_phone_number)

send_sms(outbound_text, to_phone_number)

print('start')
result = send_copilot_sms.apply_async(
    (outbound_text, to_phone_number),
    eta=datetime.now() + timedelta(seconds=5))
print('end')