def string_to_timestamp(timestring):
 ts = None
 try:
  delta = durationpy.from_str(timestring)
  past = (datetime.datetime.utcnow() - delta)
  ts = calendar.timegm(past.timetuple())
  return ts
 except Exception as e:
  pass
 if ts:
  return ts
 return 0

def string_to_timestamp ( timestring ) : ts = None try : delta = durationpy . from_str ( timestring ) past = ( datetime . datetime . utcnow ( ) - delta ) ts = calendar . timegm ( past . timetuple ( ) ) return ts except Exception as e : pass if ts : return ts return 0
accepts a str .