run display
当运行时,它吐出了错误不能写入令牌缓存到:.cache,但它仍然设法抓取正在播放的任何内容。每次发出请求时,它都会重新打开一个验证页面。它也不会保存到任何文件中。在pycharm中使用python主环境一切正常。
from spotipy.oauth2 import SpotifyOAuth
import requests
import time
#file locations
file_time_playing = "time_playing.txt"
file_time_playing_ms = "time_playing_ms.txt"
file_time_total = "time_total.txt"
file_time_total_ms = "time_total_ms.txt"
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id = ".......",
client_secret = ".......",
redirect_uri = "http://localhost:8080",
scope = "streaming"))
song = ""
def track():
print("======================")
global song
global currently_playing
# print(sp.currently_playing())
try:
currently_playing = sp.currently_playing()
#print(currently_playing)
if song == str(currently_playing["item"]["name"]):
print(song)
play_time()
return
else:
song = str(currently_playing["item"]["name"])
print(song)
with open("song.txt", "w", encoding="utf-8") as f:
f.write(song)
except:
pass
starttime = time.time()
while True:
track()
time.sleep(0.5 - ((time.time() - starttime) % 0.5))```
我发现了一个git hub错误的链接,它建议从。bat中破坏它。我使用下面的链接来解决我的问题https://github.com/plamere/spotipy/issues/363
如何使用命令行
通过批处理文件运行.py文件