def send_alert(self, alert_subscription, message):
		user = alert_subscription.user
		if not user.phone_number:
			self.logger.debug("user {0} has no cell phone number specified, skipping SMS alert".format(user.name))
			return False
		api = clockwork.API(self.config['api_key'])

		response = api.send(clockwork.SMS(user.phone_number, message)) 
		if not response.success:
			self.logger.error("received error {0} ({1})".format(response.error_code, response.error_message))
			return False
		self.logger.debug("sent an SMS alert to user {0}".format(user.name))
		return True
Esempio n. 2
0
	def on_campaign_alert(self, table, alert_subscription, count):
		user = alert_subscription.user
		if not user.phone_number:
			self.logger.debug("user {0} has no cell phone number specified, skipping SMS alert".format(user.id))
			return False
		api = clockwork.API(self.config['api_key'])

		message = "{0:,} {1} reached for campaign: {2}".format(count, table.replace('_', ' '), alert_subscription.campaign.name)
		response = api.send(clockwork.SMS(user.phone_number, message))

		if not response.success:
			self.logger.error("received error {0} ({1})".format(response.error_code, response.error_message))
			return False
		self.logger.debug("sent an SMS alert to user {0}".format(user.id))
		return True
Esempio n. 3
0
def send_message(date):
    sms_balance = float(api.get_balance()['balance'])
    if sms_balance < 0.5:
        logger.info('Clockwork sms balance is low. £{}'.format(sms_balance))

    text = 'An earlier driving test is available on {}! Book that shit fam.'.format(date)
    message = clockwork.SMS(to=PHONE_NUMBER, message=text)

    response = api.send(message)

    if response.success:
        logger.info('Text notification has been sent to {}. Response ID: {}'.format(PHONE_NUMBER, response.id))
        return arrow.get(date)

    else:
        logger.info('There has been a fucksy wucksy in the sending process!'
              'Error code: {} \nMessage: {}'.format(response.error_code, response.error_message))

        raise RuntimeError('Failed to send message. Wtf is the point of this if sending doesn\'t work?'
                           'Fix that shit.')
Esempio n. 4
0
#!/usr/bin/env python
import clockwork  #https://www.clockworksms.com

api = "[key]"
src = "[source number]"
dst = "[destination number]"
msg = "[message]"
clockwork.API(api).send(clockwork.SMS(from_name=src, to=dst, message=msg))