Skip to content

Commit a282ca9

Browse files
committed
Accept jam_date as optional argument in daily-jams patch
We want to create daily jams playlists in LB based on user timezones so that those are ready by the time they wake up. This means that the patch needs to take into account timezones when calculating the jam date to display to users. One way to do that would be to accept a timezone parameter and let the patch calculate the current day based on that. But the other way to accept a jam date directly seems more flexible and easier so doing that.
1 parent a86cc12 commit a282ca9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

troi/patches/daily_jams.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@ class DailyJamsPatch(troi.patch.Patch):
2525
@staticmethod
2626
@cli.command(no_args_is_help=True)
2727
@click.argument('user_name')
28+
@click.argument('jam_date', required=False)
2829
def parse_args(**kwargs):
2930
"""
3031
Generate a daily playlist from the ListenBrainz recommended recordings.
3132
3233
\b
3334
USER_NAME is a MusicBrainz user name that has an account on ListenBrainz.
35+
JAM_DATE is the date for which the jam is created (this is needed to account for the fact different timezones
36+
can be on different dates). Recommended formatting for the date is 'YYYY-MM-DD DAY_OF_WEEK'.
3437
"""
3538

3639
return kwargs
@@ -49,6 +52,9 @@ def description():
4952

5053
def create(self, inputs, patch_args):
5154
user_name = inputs['user_name']
55+
jam_date = inputs.get('jam_date')
56+
if jam_date is None:
57+
jam_date = datetime.utcnow().strftime("%Y-%m-%d %a")
5258

5359
raw_recs = troi.listenbrainz.recs.UserRecordingRecommendationsElement(user_name=user_name,
5460
artist_type="raw",
@@ -59,9 +65,6 @@ def create(self, inputs, patch_args):
5965
latest_filter = troi.filters.LatestListenedAtFilterElement(14)
6066
latest_filter.set_sources(raw_recs_lookup)
6167

62-
jam_date = datetime.utcnow()
63-
jam_date = jam_date.strftime("%Y-%m-%d %a")
64-
6568
pl_maker = PlaylistMakerElement(name="Daily Jams for %s, %s" % (user_name, jam_date),
6669
desc="Daily jams playlist!",
6770
patch_slug=self.slug())

0 commit comments

Comments
 (0)