Created
July 4, 2015 05:08
-
-
Save felipeborges/e4ce49970d2681ae04d2 to your computer and use it in GitHub Desktop.
Send a message to a user on Last.fm using Goa credentials
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gi.repository import Goa | |
from md5 import md5 | |
import sys | |
import requests | |
if len(sys.argv) < 3: | |
print "Usage: %s USER [MESSAGE]" % sys.argv[0] | |
sys.exit() | |
user = sys.argv[1] | |
message = sys.argv[2] | |
client = Goa.Client.new_sync(None) | |
accounts = client.get_accounts() | |
for obj in accounts: | |
account = obj.get_account() | |
if account.props.provider_name == "Last.fm": | |
oauth2 = obj.get_oauth2_based() | |
break | |
if oauth2 is None: | |
sys.exit() | |
api_key = oauth2.props.client_id | |
sk = oauth2.call_get_access_token_sync(None)[0] | |
secret = oauth2.props.client_secret | |
sig = ("api_key%smessage%smethoduser.shoutsk%suser%s%s" % | |
(api_key, message, sk, user, secret)) | |
api_sig = md5(sig).hexdigest() | |
r = requests.post("https://ws.audioscrobbler.com/2.0/", { | |
"api_key": api_key, | |
"method": "user.shout", | |
"message": message, | |
"user": user, | |
"sk": sk, | |
"api_sig": api_sig}) | |
print r.status_code, r.reason | |
print r.text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment