示例#1
0
		feeder.logError(e)
		feednow_json = None

	# If the API returns nothing, raise an alert
	if not feednow_json:
		feeder.logError("API didn't respond to Feed Now request.")
		print "Error: API didn't respond to Feed Now request."
	else:
		print "API returns: %s" % json.dumps(feednow_json, separators=(',', ': '))
	
	if feednow_json is not None:
		if feednow_json['feedNow'] == True:
			print "Feed Now request confirmed. Writing feeding amount to file..."
			if feednow_json['feedAmount']:
				# Write a "feednow.txt" file with the feed amount in it
				feeder.writeFile("%s/feednow.txt" % feednow_addr, feednow_json['feedAmount'])
				# Tell the API the feed now request is done
				try:
					print "Notifying completed Feed Now request to API"
					urllib2.urlopen(feednow_complete_url)
				except Exception, e:
					feeder.logError(e)		
			else:
				feeder.logError("Feed Now Error: Feed amount not set.")
				print "Error: Feed amount not set."		
		else:
			print "'feedNow' value returns false. No need to do anything."
	time.sleep(15)
print "feednow.py done running."
print "******************************"
				deletedID = None
				if os.path.isfile("%s%s/tagID.txt" % (settings_addr, folder)):
					deletedID = feeder.readFile("%s%s/tagID.txt" % (settings_addr, folder))
					print "Tag %s has been deleted." % folder
					print "Emptying the corresponding folder..."
					# Delete every file in the folder
					for the_file in os.listdir(settings_addr+folder):
						file_path = os.path.join(settings_addr+folder, the_file)
						try:
							if os.path.isfile(file_path):
								os.unlink(file_path)
						except Exception, e:
							feeder.logError(e)
					# Leave the "deleted.txt" file with the deleted tagID
					if not deletedID is None:
						feeder.writeFile("%s%s/deleted.txt" % (settings_addr, folder), deletedID)
						print "deleted.txt created"
	if settings_json is not None:	
		for tagNo in settings_json:
			# If folder does not exist, create one
			if not os.path.exists(settings_addr+tagNo):
				try:
					os.makedirs(settings_addr+tagNo)
				except Exception, e:
					feeder.logError(e)
					
			if settings_json[tagNo]:
				# If file does not exist, create file
				# OR
				# If 'tagUpdate' is true, a change of settings has occurred to the tag. Rewrite the corresponding files.
				if (not os.listdir("%s%s" % (settings_addr,tagNo))) or (os.listdir("%s%s" % (settings_addr,tagNo)) == [u'deleted.txt']) or (settings_json[tagNo]['tagUpdate'] == True):