I have the following code in shell:
case ${daterange} in
*[Mm][Oo]*)
factor=2592000
;;
*[Ww]*)
factor=604800
;;
*[Dd]*)
factor=86400
;;
*[Hh]*)
factor=3600
;;
*)
factor=60
;;
esac
num=`expr x"$TMFR" : x"[^0-9]*\([0-9]*\)"`
expr 0$num \* $factor
I wrote the following to convert it into python, but where I get stuck is the num= and expr lines. I dont know how to transfer them to python.
if re.search(r'[Mm][Oo]', daterange):
print "A"
elif re.search(r'[Ww]', daterange):
print "B"
elif re.search(r'[Dd]', daterange):
print "C"
elif re.search(r'[Hh]', daterange):
print "D"
elif re.search(r'[Mm]', daterange):
print "E"
else:
print "F"
daterange can contain values such as:
4h = which means 4 hours
4mo = which means 4 months
4w = which means 4 weeks
4d = which means 4 days
4m = which means 4 minutes
4s = which means 4 seconds
The goal here is to take the value in daterange and translate it into seconds.
re.search()seems overkill, asif 'mo' in daterange.lower():would work too.exprdoes? Typeman exprin your shell. You have aSTRING : REGEXPtest, so the matched text is stored innum.$TMFRhere?1mo 2w 3dis 1 month, 2 weeks, and 3 days, totaling 4060800 seconds?