mirror of
				https://github.com/KevinMidboe/Node-Com-Handler.git
				synced 2025-10-29 17:50:27 +00:00 
			
		
		
		
	Added more error detection, but need moar
This commit is contained in:
		| @@ -3,7 +3,7 @@ | |||||||
| # @Author: KevinMidboe | # @Author: KevinMidboe | ||||||
| # @Date:   2017-01-27 19:48:42 | # @Date:   2017-01-27 19:48:42 | ||||||
| # @Last Modified by:   KevinMidboe | # @Last Modified by:   KevinMidboe | ||||||
| # @Last Modified time: 2017-02-03 12:33:51 | # @Last Modified time: 2017-02-18 11:49:30 | ||||||
|  |  | ||||||
| # TODO add better error handling to return statements | # TODO add better error handling to return statements | ||||||
|  |  | ||||||
| @@ -14,8 +14,7 @@ def secToDay(seconds): | |||||||
| 	days = int(seconds/86400) | 	days = int(seconds/86400) | ||||||
| 	if days is 1: | 	if days is 1: | ||||||
| 		return str(days)+' day' | 		return str(days)+' day' | ||||||
| 	else: | 	return str(days)+' days' | ||||||
| 		return str(days)+' days' |  | ||||||
|  |  | ||||||
| def secToHour(seconds): | def secToHour(seconds): | ||||||
| 	hours = (seconds)//3600 | 	hours = (seconds)//3600 | ||||||
| @@ -28,16 +27,15 @@ def timeSinceBoot(): | |||||||
| 	currTime = time() 	# Use 'time()' to get seconds currently | 	currTime = time() 	# Use 'time()' to get seconds currently | ||||||
| 	deltaSeconds = int(currTime-bootTime)  | 	deltaSeconds = int(currTime-bootTime)  | ||||||
|  |  | ||||||
| 	# Return in day format | 	if deltaSeconds >= 86400: # Return in day format | ||||||
| 	if deltaSeconds >= 86400: | 		uptime = secToDay(deltaSeconds) | ||||||
| 		return secToDay(deltaSeconds) |  | ||||||
|  |  | ||||||
| 	# Return in hour format |  | ||||||
| 	elif deltaSeconds < 86400 and deltaSeconds >= 0: | 	elif deltaSeconds < 86400 and deltaSeconds >= 0: | ||||||
| 		return secToHour(deltaSeconds) | 		uptime = secToHour(deltaSeconds) | ||||||
| 	else: | 	else: | ||||||
| 		# TODO Throw error | 		return {"errors": "Uptime not found"} | ||||||
| 		return None |  | ||||||
|  | 	return {"uptime": uptime} | ||||||
|  |  | ||||||
| if __name__=="__main__": | if __name__=="__main__": | ||||||
| 	print(timeSinceBoot()) | 	print(timeSinceBoot()) | ||||||
		Reference in New Issue
	
	Block a user