2020-07-07 23:26:47 +09:00
|
|
|
import sys
|
|
|
|
import datetime
|
|
|
|
from yandex_music.client import Client
|
|
|
|
|
|
|
|
# Help text
|
2021-02-03 21:47:27 +09:00
|
|
|
if len(sys.argv) == 1 or len(sys.argv) > 3:
|
2020-07-07 23:26:47 +09:00
|
|
|
print('Usage: DailyPlaylistUpdater.py token')
|
2021-02-03 21:47:27 +09:00
|
|
|
print('token - Authentication token')
|
2020-07-07 23:26:47 +09:00
|
|
|
quit()
|
|
|
|
# Authorization
|
2021-02-03 21:47:27 +09:00
|
|
|
elif len(sys.argv) == 2:
|
2022-02-20 02:59:53 +09:00
|
|
|
client = Client(sys.argv[1]).init()
|
2020-07-07 23:26:47 +09:00
|
|
|
|
|
|
|
# Current daily playlist
|
2021-02-03 21:47:27 +09:00
|
|
|
PersonalPlaylistBlocks = client.landing(blocks=['personalplaylists']).blocks[0]
|
|
|
|
DailyPlaylist = next(
|
|
|
|
x.data.data for x in PersonalPlaylistBlocks.entities if x.data.data.generated_playlist_type == 'playlistOfTheDay'
|
|
|
|
)
|
2020-07-07 23:26:47 +09:00
|
|
|
|
|
|
|
# Check if we don't need to update it
|
2021-02-03 21:47:27 +09:00
|
|
|
if DailyPlaylist.play_counter.updated:
|
2020-07-07 23:26:47 +09:00
|
|
|
modifiedDate = datetime.datetime.strptime(DailyPlaylist.modified, "%Y-%m-%dT%H:%M:%S%z").date()
|
2021-02-03 21:47:27 +09:00
|
|
|
if datetime.datetime.now().date() == modifiedDate:
|
2020-07-07 23:26:47 +09:00
|
|
|
print('\x1b[6;30;43m' + 'Looks like it has been already updated today' + '\x1b[0m')
|
|
|
|
quit()
|
|
|
|
|
|
|
|
# Updated playlist
|
|
|
|
updatedPlaylist = client.users_playlists(user_id=DailyPlaylist.uid, kind=DailyPlaylist.kind)[0]
|
|
|
|
|
2021-02-03 21:47:27 +09:00
|
|
|
if updatedPlaylist.play_counter.updated and not DailyPlaylist.play_counter.updated:
|
2020-07-07 23:26:47 +09:00
|
|
|
print('\x1b[6;30;42m' + 'Success!' + '\x1b[0m')
|
|
|
|
else:
|
|
|
|
print('\x1b[6;30;41m' + 'Something has gone wrong and nothing updated' + '\x1b[0m')
|
|
|
|
|
|
|
|
# Debug information
|
|
|
|
print('Before:\n modified: %s\n PlayCounter: %s' % (DailyPlaylist.modified, DailyPlaylist.play_counter))
|
2021-02-03 21:47:27 +09:00
|
|
|
print('After:\n modified: %s\n PlayCounter: %s' % (updatedPlaylist.modified, updatedPlaylist.play_counter))
|