Beispiel #1
0
def process_message(msg):
	print "process_message"	

	ph = plxaddr.parse_headers(msg)		# This should render lots of useful information.  No, seriously.
	#print ph
	if (ph == None):
		print "Garbled headers, rejecting"
		return

	contents = msg.get_payload()
	if validate_payload(contents):
		print "Contents valid"
	else:
		print "Contents invalid"
		return
	content_object = json.loads(contents)	# Now we have a lovely object with stuff in it

	# Is there anything more fun than a state machine?  I thought not.
	if (ph['listened']):
		print "We are listening, so we DQ this"
		state = ph['plexus-identifier']
		if (state.find(u'plexus-update') == 0):			# Twitter updates, etc.
			print "LISTENED UPDATE"
			print "Sending it to the DQ"
			pluid = contents_to_pluid(contents)
			dq.send_listened(ph['tracking_id'], state, pluid, content_object['when'], contents)	# Pop it onto the DQ
		elif (state.find(u'plexus-message') == 0):			# Twitter DMs, emails, FB messages, etc.
			print "LISTENED MESSAGE"
			pluid = contents_to_pluid(contents)
			dq.send_listened(ph['tracking_id'], state, pluid, content_object['when'], contents)	# Pop it onto the DQ
		elif (state.find(u'plexus-post') == 0):			# RSS, for example
			print "LISTENED POST"
		elif (state.find(u'plexus-command') == 0):			# Plexus commands <- very important
			print "LISTENED COMMAND"
	else:
		print "We are sharing, so we NQ this"
		state = ph['plexus-identifier']
		if (state.find(u'plexus-update') == 0):			# Twitter updates, etc.
			print "SHARED UPDATE"
			print "Sending it to the DQ"
			nq.send_shared(ph['tracking_id'], state, "", content_object['when'], contents)	# Pop it onto the NQ
		elif (state.find(u'plexus-message') == 0):			# Twitter DMs, emails, FB messages, etc.
			print "SHARED MESSAGE"
			pluid = outgoing_message_to_pluid(contents)
			print 'pluid: %s' % pluid
			nq.send_shared(ph['tracking_id'], state, pluid, content_object['when'], contents)	# Pop it onto the NQ
Beispiel #2
0
def process_message(msg):
	print "process_message"	

	ph = plxaddr.parse_headers(msg)		# This should render lots of useful information.  No, seriously.
	#print ph
	if (ph == None):
		print "Garbled headers, rejecting"
		return

# 	msgid = msg['Subject']		# Should have a UUID therein - some way to validate this?
# 	
# 	mfrom = msg['From']		# Get the addressee information
# 	f = unpack_sender(mfrom)
# 	print f
# 
# 	mto = msg['To']
# 	to = unpack_to(mto)
# 	print to
# 
# 	if validate_type(to['type']):
# 		print "Type valid"
# 	else:
# 		print "Type invalid"
# 		return

	contents = msg.get_payload()
	if validate_payload(contents):
		print "Contents valid"
	else:
		print "Contents invalid"
		return
	content_object = json.loads(contents)	# Now we have a lovely object with stuff in it
	
	# If this is an update, we should send an update out 
	# If this is a message, we should send a DM
# 	if (to['type'].find(u'plexus-update') == 0):
# 		stat = do_sendUpdate(content_object)
# 	elif (to['type'].find(u'plexus-message') == 0):
# 		do_sendDM(content_object)

	if (ph['plexus-identifier'].find(u'plexus-update') == 0):
		stat = do_sendUpdate(content_object)
	elif (ph['plexus-identifier'].find(u'plexus-message') == 0):
		do_sendDM(content_object)