Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. from bs4 import BeautifulSoup
  2. from urllib.parse import urlencode
  3. from urllib.request import urlopen
  4.  
  5. # -*- coding: utf-8 -*-
  6.  
  7. """
  8.  
  9. using UTF-8 encoding for LFM API
  10.  
  11. Methods for LFM:
  12.  
  13. artist.getInfo
  14. album.getInfo
  15. track.getInfo
  16.  
  17. """
  18. #Account:
  19. USER = "alla_cobra"
  20. API_KEY = "f3bd5b0d18985e1b0d4bdc458879a39a"
  21.  
  22. def artistQuery(artist):
  23.     data = {'method' : 'artist.getInfo','user' : USER,'api_key' : API_KEY,'artist' : artist}
  24.     res = 'http://ws.audioscrobbler.com/2.0/?' + urlencode(data)
  25.     return res
  26.  
  27. def trackQuery(artist, title):
  28.     data = {'method' : 'track.getInfo','user' : USER,'api_key' : API_KEY,'artist' : artist,'track' : title}
  29.     res = 'http://ws.audioscrobbler.com/2.0/?' + urlencode(data)
  30.     return res
  31.  
  32. def getArtistScrobbles(artist):
  33.     url = artistQuery(artist)
  34.     res = urlopen(url)
  35.     soup = BeautifulSoup(res, "html.parser")
  36.     return soup.track.playcount.get_text()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement