Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import os
- import json
- URL_TRACK = 'https://api.spotify.com/v1/me/player/currently-playing'
- URL_STATUS = "https://api.vk.com/method/status.set"
- VK_TOKEN = os.environ.get('VK_TOKEN')
- SP_TOKEN = os.environ.get('SP_TOKEN')
- def set_status():
- params = {
- 'user_id': 8573490,
- 'v': 5.92,
- 'access_token': VK_TOKEN,
- 'text': current_track()
- }
- status = requests.get(url=URL_STATUS, params=params)
- def track_data():
- headers = {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- 'Authorization': f'Bearer {SP_TOKEN}',
- }
- return requests.get(url=URL_TRACK, headers=headers)
- def track_is_playing():
- return track_data().status_code == 200
- def current_track():
- data = track_data().json()
- artist_path = data["item"]['artists'][0]['name']
- track_path = data["item"]['name']
- return(f'{artist_path} - {track_path}')
- def run_script():
- if track_is_playing():
- set_status()
- print(current_track())
- else:
- print('Not playing')
- if __name__ == "__main__":
- run_script()
Add Comment
Please, Sign In to add comment