我正在获取我的50位顶级艺术家artistList
的列表。从此列表中,我得到artistAlbumsList
中每位艺术家的专辑,然后从中循环浏览艺术家专辑的曲目,直到在albumTracks
中找到明确的曲目。
(Spotify不会将专辑标记为明确的专辑,仅将曲目标记为...这就是为什么我必须遍历曲目。)
如果有明确的曲目,我将专辑标记为明确的曲目并将专辑添加到我的new_albums
列表中。
我怎么返回None
? 所有这些专辑中都有明确的曲目,所以这不是问题。
另外,如果我改用update
字典而不是albums
来调用new_albums
字典中的AttributeError: 'NoneType' object has no attribute 'update'
,则会收到此错误:import time
import spotipy
import spotipy.util as util
from config import spotify_token
def albumDrop():
sp = spotipy.Spotify(auth=spotify_token)
albums = {}
new_albums = {}
artistList = sp.current_user_top_artists(limit=50,offset=0,time_range='long_term')['items']
for artist in artistList:
print(artist["name"],artist["id"])
artistAlbumsList = sp.artist_albums( artist["id"],album_type='album',limit=3)['items']
for album in artistAlbumsList:
print(album['release_date'],artist['name'],album['name'],album['external_urls']['spotify'],album['id'])
albumTracks = sp.album_tracks(album['id'],limit=50)['items']
for track in albumTracks:
if track['explicit'] == True:
new_albums = albums.update({'{artistName} - {albumName}'.format(artistName = artist['name'],albumName = album['name']) : {'Release Date': album['release_date'],'Artist Name': artist['name'],'Album Name': album['name'],'Album URI': album['external_urls']['spotify'],'Album ID': album['id'],'Explicit': track['explicit']}})
break
return(new_albums)
if __name__ == "__main__":
start = time.time()
latestAlbums = albumDrop()
end = time.time()
print(latestAlbums)
print(end - start)
import cv2
import numpy as np
import pyrealsense2 as rs
import matplotlib as mpl
import matplotlib.pyplot as plt
import time
from mpl_toolkits.mplot3d import Axes3D
fig1 = plt.figure(1)
ar = fig1.gca(projection='3d')
ar.set_xlim(-1,1)
ar.set_ylim(-1,1)
ar.set_zlim(-1,1)
# Configure depth and color streams
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth,640,480,rs.format.z16,30)
config.enable_stream(rs.stream.color,rs.format.bgr8,30)
# Start streaming
pipe_profile =pipeline.start(config)
points =[[[]]]
def get_3dPoints():#Function to be written
pass
try:
while True:
# Wait for a coherent pair of frames: depth and color
frames = pipeline.wait_for_frames()
depth_frame = frames.get_depth_frame()
color_frame = frames.get_color_frame()
if not depth_frame or not color_frame: #or not infrared_frame:
continue
# Convert images to numpy arrays
depth_image = np.asanyarray(depth_frame.get_data())
color_image = np.asanyarray(color_frame.get_data())
cv2.namedwindow('RealSense',cv2.WINDOW_AUTOSIZE)
colorizer = rs.colorizer()
depth_colormap = np.asanyarray(colorizer.colorize(depth_frame).get_data())
cv2.imshow('RealSense',depth_colormap)
"""
points = get_3dPoints()
tgt = ar.scatter(points,'red')
ar.set_xlabel('X - axis')
ar.set_ylabel('Y - axis')
ar.set_zlabel('Z - axis')
plt.pause(0.00000000000000001)
tgt.remove()
"""
cv2.waitKey(1)
finally:
# Stop streaming#img = cv2.resize(img,(1280,720),interpolation=cv2.INTER_AREA)
pipeline.stop()
有没有更快的方法可以做到这一点?