我试图用这个python脚本来实现的是,在祈祷的时候阻止spotify播放,但它似乎从来没有起过作用,尽管我读了几十篇关于开发人员和chatgpt对话的spotify的文章,这就是我最终得到的:
import requests
import datetime
import geocoder
import time
import spotipy
from spotipy.oauth2 import SpotifyOAuth
# Set your Spotify app credentials (client ID and client secret)
client_id = YOUR_CLIENT_ID
client_secret = YOUR_CLIENT_SECRET
redirect_uri = YOUR_REDIRECT_URI
def get_prayer_times(latitude, longitude):
today = datetime.date.today()
formatted_date = today.strftime( %Y-%m-%d )
# Get the prayer times for today
url = f"https://api.aladhan.com/v1/timings/{formatted_date}?latitude={latitude}&longitude={longitude}&method=2"
response = requests.get(url)
data = response.json()
prayer_times = data[ data ][ timings ]
keys_to_remove = [ Sunrise , Sunset , Midnight , Imsak , Firstthird , Lastthird ]
# Remove unnecessary keys from the prayer times dictionary
for key in keys_to_remove:
prayer_times.pop(key, None)
return prayer_times
def get_ip_address():
response = requests.get( https://api.ipify.org?format=json )
ip_data = response.json()
ip_address = ip_data[ ip ]
return ip_address
def get_latitude_longitude(ip_address):
g = geocoder.ip(ip_address)
if g.ok:
latitude, longitude = g.latlng
return latitude, longitude
else:
return None
def pause_spotify():
devices = sp.devices()
for device in devices[ devices ]:
if device[ is_active ]:
sp.pause_playback(device[ id ])
def resume_spotify():
devices = sp.devices()
for device in devices[ devices ]:
if device[ is_active ]:
sp.start_playback(device[ id ])
def main():
ip_address = get_ip_address()
location = get_latitude_longitude(ip_address)
if location:
latitude, longitude = location
prayer_times = get_prayer_times(latitude, longitude)
print("Prayer Times:")
print(prayer_times)
# Get current time
current_time = datetime.datetime.now().strftime( %H:%M )
for prayer, time_value in prayer_times.items():
if current_time >= time_value:
# Prayer time has passed
print(f"{prayer} time has passed.")
pause_spotify()
else:
# Prayer time has not yet arrived
print(f"{prayer} time is yet to come.")
resume_spotify()
break
if __name__ == __main__ :
auth_manager = SpotifyOAuth(client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri)
sp = spotipy.Spotify(auth_manager=auth_manager)
main()
now i get how to get my client_id and client_secret from my spotifyfordeveloppers dashboard but i could never understand how i cant get that redirect uri although i read in some places that u can fill it with any spotify related link, but i always get the following error i couldn t solve: sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials(client_id=client_id, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: Spotify.init() got an unexpected keyword argument auth_manager
注意:一般来说,我还是一个使用API和编码的初学者,但我对python和编码基础知识几乎无所不知。非常感谢。
。。。。。。。。。。。。。。。。。。。。。。。。。