data['timestamp'] = datetime.datetime.utcnow().isoformat() try: users = data['users'] except KeyError: print("Could not find 'users' in data.json, exiting...", file=sys.stderr) exit(1) try: oldplaylists = data['playlists'] except KeyError: print("Could not find 'playlists' in data.json, exiting...", file=sys.stderr) exit(1) sp = spotifywebapi.Spotify(CLIENT_ID, CLIENT_SECRET) executor = ThreadPoolExecutor() futures = [] tempplaylists = {} temptracks = {} for user in users: futures.append(executor.submit(runUser, user)) wait(futures) print('Finished pulling data') executor.shutdown() realplaylists = {} for us, newuserplaylists in tempplaylists.items(): if newuserplaylists: realplaylists[us] = newuserplaylists
print('updating last 100 RPOS') userme = getAuthUser(userFile['users'][0]) rpos = sp.getPlaylistFromId('5WYRn0FxSUhVsOQpQQ0xBV') total = rpos['tracks']['total'] offset = total - 100 tracks = sp.getTracksFromItem(rpos) uris = [i['track']['uri'] for i in tracks[offset:] if i['is_local'] is False] userme.replacePlaylistItems('1iAyKjAS15OOlFBFtnWX1n', uris) print('finished last 100 RPOS') date = datetime.datetime.today() refreshtokenme = os.getenv('REFRESHTOKENME') try: sp = spotifywebapi.Spotify( os.getenv('CLIENT_ID'), os.getenv('CLIENT_SECRET')) except spotifywebapi.SpotifyError as err: print('Error loading bot') print(err) exit() botuser = sp.getAuthUser(refreshtokenme) if __name__ == '__main__': with open(sys.path[0] + '/data.json') as json_file: userFile = json.load(json_file) update() last100RandomPool() else: with open('./data.json') as json_file: userFile = json.load(json_file)