-
Notifications
You must be signed in to change notification settings - Fork 0
/
maintainer.py
executable file
·46 lines (35 loc) · 1.34 KB
/
maintainer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python
import sys
import time
import calendar
import playlist
import manager
import kcrw
import credentials
def maintain_kcrw_playlists(base_path, up_to_date, playlist_manager=None):
playlist_updater = kcrw.PlaylistUpdater(base_path)
year = up_to_date.tm_year
month = up_to_date.tm_mon
(_, num_days_in_month) = calendar.monthrange(year, month)
for day in range(1, (min(num_days_in_month, up_to_date.tm_mday)+1)):
ret = playlist_updater.update(year, month, day)
if ret == 1:
print "Can't go further than {0}/{1}/{2}".format(month, day, year)
break
if playlist_manager:
(play_list, play_list_name,
file_name) = playlist_updater.get_playlist(year, month)
def skip_filter(entry):
for s in entry.sources:
if 'ECLECTIC' in s or 'eclectic' in s:
return False
return True
name = play_list_name + '-mbe'
playlist_manager.update_playlist(play_list, name, skip_filter)
play_list.to_json_file(file_name)
if len(sys.argv) < 2:
sys.exit('Usage: %s base-path' % sys.argv[0])
base_path = sys.argv[1]
playlist_manager = manager.Manager.create('Spotify', credentials)
yesterday = time.localtime(time.time() - (60*60*24 - 1))
maintain_kcrw_playlists(base_path, yesterday, playlist_manager)