def sonarr():
	postData = json.loads(request.data)
	seriesTitle = postData['Series']['Title']
	episodeSeasonNumber = str(postData['Episodes'][0]['SeasonNumber'])
	episodeEpisodeNumber = str(postData['Episodes'][0]['EpisodeNumber'])
	episodeEpisodeTitle = postData['Episodes'][0]['Title']
	episodeEpisodeQuality = str(postData['Episodes'][0]['Quality'])
	downloadedEpisode =  'Sonarr: Downloaded - ' +  seriesTitle + ' - ' + episodeSeasonNumber + 'x' + episodeEpisodeNumber + ' - ' + episodeEpisodeTitle + ' [' + episodeEpisodeQuality + ']'
	lametricNotify.notify(config, downloadedEpisode, lametricIcon='a406')
	return "OK"
def spark():
	postData = json.loads(request.data)
	personId = postData['data']['personId']
	roomId = postData['data']['roomId']
	messageId = postData['data']['id']
	personEmail = postData['data']['personEmail']
	creationTime = postData['data']['created']
	event = postData['event']
	if personId != sparkApi.get(config, getMethod='myPersonId'):
		sparkPool = ThreadPool(processes=2)
		personDisplayNameResult = sparkPool.apply_async(sparkApi.get, (config,), dict(getMethod='personId', getMethodData=personId))
		personMessageResult = sparkPool.apply_async(sparkApi.get, (config,), dict(getMethod='messageId', getMethodData=messageId))
		personDisplayName = personDisplayNameResult.get()
		personMessage = personMessageResult.get()
		smartHomeResult = smartHome.analyzeMessage(personMessage)
		notSmartHomeTask = False
		for key in smartHomeResult:
			if smartHomeResult[key] == None:
				notSmartHomeTask = True
				break
		if notSmartHomeTask:
			notifyMessage = 'Spark: Message from ' + personDisplayName + ": " + personMessage
			lametricNotify.notify(config, notifyMessage, lametricIcon='a1106')	
		else:
			if smartHome.action(config, smartHomeResult):
				deviceType = smartHomeResult['DeviceType']
				location = smartHomeResult['Location']
				action = smartHomeResult['Action']
				notifyMessage = deviceType + ' in ' + location + ' is now in State: ' + action
				smartHomeThread =  threading.Thread(target=smartHome.action, args=(config, smartHomeResult))
				lametricNotifyThread =  threading.Thread(target=lametricNotify.notify, args=(config, notifyMessage), kwargs=dict(lametricIcon='i96'))
				sparkApiThread = threading.Thread(target=sparkApi.post, args=(config, postData, notifyMessage), kwargs=dict(action='createMessage'))
				lametricNotifyThread.start()
				sparkApiThread.start()
			else:
				print "Smart Home Action Aborted"
	else:
		print 'Webhook Post Request Not Processed'
	return  "OK"
def couchpotato():
	postData = json.loads(request.data)
	postMessage = postData['message']
	lametricNotify.notify(config, postMessage, lametricIcon='a406')
	return "OK"