Skip to content

Instantly share code, notes, and snippets.

@dewey
Created December 22, 2014 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dewey/f2725f51857607e52093 to your computer and use it in GitHub Desktop.
Save dewey/f2725f51857607e52093 to your computer and use it in GitHub Desktop.
munin-lastfm
#!/usr/bin/env python
import urllib.request
import json
import sys
def main():
try:
mode = sys.argv[1]
except IndexError:
mode = ""
if mode == "suggest":
print("playcount")
sys.exit(0)
if mode == "config":
print("graph_title Last.FM Playcount")
print("graph_vlabel Tracks scrobbled")
print("graph_category Last.FM")
print("playcount.label Tracks")
sys.exit(0)
else:
# Replace username and API key: http://www.last.fm/api/account/create
response = urllib.request.urlopen('http://ws.audioscrobbler.com/2.0/?method=user.getinfo&user=USERNAME&api_key=APIKEY&format=json')
content = response.read()
data = json.loads(content.decode('utf8'))
print("playcount.value", data["user"]["playcount"])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment