Skip to content

Commit

Permalink
Added support for multiple date formats
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-parlette committed Jun 8, 2016
1 parent 3f41d36 commit d919b9b
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions czaban/czaban
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ from subprocess import call

today = datetime.date.today()

# They seem to regularly change the date format, I think it's just to mess with
# me. This is a list of all I've seen.
date_formats = [
'%-m-%d-%Y',
'%m-%d-%y',
]

parser = argparse.ArgumentParser(description='Find a czaban podcast'
' and play it on sonos. If the podcast'
' is not found, it will keep trying'
Expand Down Expand Up @@ -60,15 +67,22 @@ while not (url or args.exit_if_not_found):
html = response.read()

# https://audioboom.com/boos/4078524-1-19-2016-czaban-hour-1
match = re.search("https://audioboom.com/boos/"
".*-{}-czaban-hour-{}".format(
args.date,
args.hour),
html)
if match and match.group(0):
url = match.group(0)
log.debug("Found URL of {}".format(url))
else:
# Add the date passed in as an argument to the date_formats list
date_formats.append(args.date)
for date in date_formats:
log.debug("Searching for date format '{}'...".format(date))
match = re.search("https://audioboom.com/boos/"
".*-{}-czaban-hour-{}".format(
date,
args.hour),
html)
if match and match.group(0):
url = match.group(0)
log.debug("Found URL of {}".format(url))
break

if url is None:
# If we made it here, then no URL was found
log.warning("Hour {} not found, waiting to retry...".format(
args.hour))
if args.debug:
Expand Down

0 comments on commit d919b9b

Please sign in to comment.