kratsg / optimization

Code for optimizing simple n-tuples
http://giordonstark.com/
MIT License
7 stars 9 forks source link

Parse DSID from directory-based structure as well #68

Closed kratsg closed 7 years ago

kratsg commented 8 years ago
#@echo(write=logger.debug)
did_regex = re.compile('\.?(?:00)?(\d{6,8})\.?')
def get_did(filename):
  global did_regex
  m = did_regex.search(filename.split("/")[-2])
  if m is None:
    logger.warning('Can\'t figure out the DID! Trying format II ...')
    m = did_regex.search(filename.split("/")[-1])
  if m is None:
    logger.warning('Can\'t figure out the DID! Using input filename ...')
    return filename.split("/")[-1]
  return m.group(1)