Skip to content

Instantly share code, notes, and snippets.

@arastu
Last active November 27, 2020 19:52
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arastu/15bf96fc6e0bbd4d9617def5c40af14d to your computer and use it in GitHub Desktop.
Save arastu/15bf96fc6e0bbd4d9617def5c40af14d to your computer and use it in GitHub Desktop.
update twitter bio and add current playing song from Spotify to it
on escape_quotes(string_to_escape)
set AppleScript's text item delimiters to the "\""
set the item_list to every text item of string_to_escape
set AppleScript's text item delimiters to the "\\\""
set string_to_escape to the item_list as string
set AppleScript's text item delimiters to ""
return string_to_escape
end escape_quotes
tell application "Spotify"
set ctrack to "{"
set ctrack to ctrack & "\"artist\": \"" & my escape_quotes(current track's artist) & "\""
set ctrack to ctrack & ",\"album\": \"" & my escape_quotes(current track's album) & "\""
set ctrack to ctrack & ",\"disc_number\": " & current track's disc number
set ctrack to ctrack & ",\"duration\": " & current track's duration
set ctrack to ctrack & ",\"played_count\": " & current track's played count
set ctrack to ctrack & ",\"track_number\": " & current track's track number
set ctrack to ctrack & ",\"popularity\": " & current track's popularity
set ctrack to ctrack & ",\"id\": \"" & current track's id & "\""
set ctrack to ctrack & ",\"name\": \"" & my escape_quotes(current track's name) & "\""
set ctrack to ctrack & ",\"album_artist\": \"" & my escape_quotes(current track's album artist) & "\""
set ctrack to ctrack & ",\"artwork_url\": \"" & current track's artwork url & "\""
set ctrack to ctrack & ",\"spotify_url\": \"" & current track's spotify url & "\""
set ctrack to ctrack & "}"
end tell
import tweepy
import osascript
import json
def main():
api_key = "API_KEY_HERE"
api_secret = "API_SECRET_HERE"
access_token = "ACCESS_TOKEN_HERE"
access_token_secret = "ACCESS_TOKEN_SECRET_HERE"
auth = tweepy.OAuthHandler(api_key, api_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
current_bio = "So many technologies, so little time. semi-hipster software developer."
_, current_track, _ = osascript.run("current_track.applescript")
# TODO handel errors :|
track_dict = json.loads(current_track)
api.update_profile(
description = "{} #nowPlaying🎧: {} - {}".format(current_bio, track_dict['name'], track_dict['artist'])
)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment