#!/usr/bin/python

#
# sectotime.py v1.0 - 2006/08
#
# this script converts a time string in seconds into a string with the
# representation of the same time in days, hours and minutes.
#
# Copyright (C) 2006 by Pedro Venda < pjvenda (at) pjvenda org >
#
# Distributed under the terms of the GNU Public License Agreement (GPLv2)
# http://www.fsf.org/licensing/licenses/gpl.html or
# http://www.fsf.org/licensing/licenses/gpl.txt
#
# Usage
# =====
#
# this script receives its input from stdin and outputs it into stdout
# example: $ echo "10000" | ./sectotime.py
#          2h 46m 40s
#          $
# alternatively, the time input can be given as a command line argument
# example: $ ./sectotime.py 10000
#          2h 46m 40s
# finally it can be included as a module called "sectotime" and provides
# the function sectotime(seconds)
#
# Changelog
# =========
#
# v1.0 - 2006/08/20
# - initial version
#

"""
Converter of seconds to a time string in minutes, hours and days
"""

__author__ = "Pedro Venda (pjvenda at pjvenda org)"
__version__ = "1.0"
__date__ = "2006/08/20"
__copyright__ = "Copyright (c) 2006 Pedro Venda"
__license__ = "GPL"

# constants: Seconds in a day, seconds in an hour, seconds in a minute
constant={'DAY':60*60*24,'HOUR':60*60,'MINUTE':60}

def sectotime(seconds):
	"""Convert an arbitrary number of seconds into a human readable
	time string in days, hours, minutes and seconds.
	
	An output like "jd kh lm ms" means that the given amount of seconds
	correspond to j days, k hours, l minutes and m seconds."""
	
	# try to sanitize input
	uptime=int(abs(float(sdata)))
	# retrieve number of days
	days=uptime / constant['DAY']
	# obtain time left
	left=uptime - (days*constant['DAY'])
	# retrieve number of hours left
	hours=left / constant['HOUR']
	# obtain time left
	left=left - (hours*constant['HOUR'])
	# retrieve number of minutes left
	mins=left / constant['MINUTE']
	# obtain time left
	left=left - (mins*constant['MINUTE'])
	# remaining time is number of seconds left
	secs=left

	# process output string
	timestr="%ds" % (secs,)
	if mins:
		timestr="%dm %s" % (mins,timestr)
	if hours:
		timestr="%dh %s" % (hours,timestr)
	if days:
		timestr="%dd %s" % (days,timestr)
	# return the result
	return timestr

# see how we've been called
if __name__ == "__main__":
	# we've been invoked directly

	# import command line arguments
	from sys import argv

	# where do we get our input?
	if len(argv) >= 2:
		# command line argument
		sdata=argv[1]
	else:
		# stdin
		sdata=raw_input().split(' ')[0]

	# process input
	timestr=sectotime(sdata)
	# and print result
	print timestr
