refactor
This commit is contained in:
parent
1ad3740677
commit
6ef42c9fee
1 changed files with 68 additions and 64 deletions
34
re.py
34
re.py
|
@ -46,7 +46,22 @@ class Pandora:
|
|||
'keys': keys
|
||||
})['data']
|
||||
|
||||
def get_playlists():
|
||||
class Engine:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def _shift_clips(clips):
|
||||
index = random.randrange(len(clips))
|
||||
return clips[index:] + clips[:index - 1]
|
||||
|
||||
def get_videos(user):
|
||||
products = []
|
||||
for event in user['events']:
|
||||
if 'product' in event['data']:
|
||||
products.append(event['data']['product'])
|
||||
|
||||
def update(self):
|
||||
# Get all storylines with tags
|
||||
storylines = [{
|
||||
'name': entity['name'],
|
||||
|
@ -83,7 +98,6 @@ def get_playlists():
|
|||
with open(filename, 'w') as f:
|
||||
f.write(json.dumps(videos, indent=4, sort_keys=True))
|
||||
order = {video['id']: video['order'] for video in videos}
|
||||
print(order)
|
||||
# Sort clips
|
||||
clips = sorted(
|
||||
clips,
|
||||
|
@ -100,20 +114,10 @@ def get_playlists():
|
|||
]
|
||||
} for storyline in storylines] if playlist['clips']]
|
||||
|
||||
def get_videos(user):
|
||||
products = []
|
||||
for event in user['events']:
|
||||
if 'product' in event['data']:
|
||||
products.append(event['data']['product'])
|
||||
|
||||
def shift_clips(clips):
|
||||
index = random.randrange(len(clips))
|
||||
return clips[index:] + clips[:index - 1]
|
||||
|
||||
if __name__ == '__main__':
|
||||
pandora = Pandora()
|
||||
playlists = get_playlists()
|
||||
with open('playlists.json', 'w') as f:
|
||||
engine = Engine()
|
||||
playlists = engine.update()
|
||||
with open('json/playlists.json', 'w') as f:
|
||||
f.write(json.dumps(playlists, indent=4, sort_keys=True))
|
||||
print(len(playlists), 'playlists')
|
||||
|
||||
|
|
Loading…
Reference in a new issue