Commit 56081ca0 authored by prg's avatar prg Committed by Sébastien Helleu

lastfm.py 0.8: port script to Python 3 only

parent 03ff6881
......@@ -11,6 +11,9 @@
license: GPLv3
history:
0.8 - 2020-03-18, prg <[email protected]>
Port to python3
0.7 - 2016-01-29, timss <[email protected]>
Fix UnicodeEncodeError
......@@ -37,7 +40,7 @@
import weechat
import requests
weechat.register("lastfm", "Adam Saponara", "0.7", "GPL3", "Sends your latest Last.fm track to the current buffer", "", "")
weechat.register("lastfm", "Adam Saponara", "0.8", "GPL3", "Sends your latest Last.fm track to the current buffer", "", "")
defaults = {
"lastfm_username" : "yourusername",
......@@ -49,7 +52,7 @@ cmd_buffer = ""
cmd_stdout = ""
cmd_stderr = ""
for k, v in defaults.iteritems():
for k, v in defaults.items():
if not weechat.config_is_set_plugin(k):
weechat.config_set_plugin(k, v)
......@@ -61,16 +64,16 @@ def lastfm_cmd(data, buffer, args):
cmd_buffer = buffer
cmd_stdout = ""
cmd_stderr = ""
python2_bin = weechat.info_get("python2_bin", "") or "python"
python3_bin = weechat.info_get("python3_bin", "") or "python"
cmd_hook_process = weechat.hook_process(
python2_bin + " -c \"\n"
python3_bin + " -c \"\n"
"import sys, requests\n"
"r = requests.get('https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=%(username)s&api_key=618f9ef38b3d0fed172a88c45ae67f33&format=json&limit=1&extended=0')\n"
"if not r.status_code == requests.codes.ok:\n"
" print >>sys.stderr, 'Could not fetch Last.fm RSS feed.',\n"
" exit()\n"
"json = r.json()['recenttracks']['track'][0]\n"
"print('{} – {}'.format(json['artist']['#text'].encode('utf-8'), json['name'].encode('utf-8'))),\n"
"print('{} – {}'.format(json['artist']['#text'], json['name'])),\n"
"\"" % {"username" : weechat.config_get_plugin('lastfm_username')},
10000, "lastfm_cb", "")
return weechat.WEECHAT_RC_OK
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment