Exemple #1
0
def index():
	#try:
	to = request.form['to']

	#match tweet
	tweet_match = re.search('([\w]*)\+([\d]*)@maintenance.livelovely.com', to)
	if tweet_match is not None:
		reply_user = tweet_match.group(1)
		print reply_user
		in_reply_to = tweet_match.group(2)
		print in_reply_to

	sms_match = re.search('([\d]*)@maintenance.livelovely.com', to)
	if sms_match is not None:
		from_sms = sms_match.group(1)
		print from_sms

	twitter = False
	sms = False
	if tweet_match is not None:
		user_email = users[reply_user]
		twitter = True
	else:
		sms = True
		user_email = users[from_sms]

	#forward email
	from_ad = request.form['envelope'][1]
	text = request.form['html']
	_sendHtmlEmail(from_ad, user_email, 'RE:Lovely Maintenance Request', None, text, request.form['from'])
	print 'email'

	if twitter is True:
		poop.i += 1
		#create twitter
		t = Twitter(
			auth=OAuth(oauth_token, oauth_secret,
				consumer_key, consumer_secret)
		)
		try:
			tweet = '%s Check your email for your landlord\'s response! Rate their repair by replying 1-5 (5=best) to this tweet. #%s' % ('@'+reply_user, str(poop.i))
			t.statuses.update(status=tweet, in_reply_to_status_id=in_reply_to)
			print 'tweet'
		except Exception as ex:
			pass

	if sms is True:
		client = TwilioRestClient(twilio_sid, twilio_token)
		message = client.sms.messages.create(to=from_sms, from_="+14842402676",
		body="Check your email for your landlord\'s response! Rate their repair by replying 1-5 (5=best) to this text.'")
	#except Exception as ex:
	#	raise ex
	#finally:
	return '1'
Exemple #2
0
def send_email_to_user(user, type, from_number, text):
	print 'Sending Email'
	c = dict()
	c['type'] = type
	c['name'] = tenet_user[from_number]['name']
	c['text'] = text
	c['first'] = False

	env = Environment(loader=PackageLoader('tweetslice', 'templates'))
	tmp = env.get_template('general.html')
	html = tmp.render({'c':c})
	#html = render('/messages/alert.html')
	from_ad = '*****@*****.**' % (str(from_number[1:]))

	subject = "Request to fix %s's maintenance issue" % (tenet_user[from_number]['name'])

	_sendHtmlEmail(from_ad, user['email'], subject ,None, html, 'Lovely FixIt', user['name'])