Created
December 22, 2014 23:53
-
-
Save dewey/f2725f51857607e52093 to your computer and use it in GitHub Desktop.
munin-lastfm
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
#!/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