Guest User

Untitled

a guest
May 22nd, 2012
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.92 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import os
  3. import webbrowser
  4. import urllib2
  5. import lxml
  6. import lxml.html
  7.  
  8. #our functions to check program
  9. def CheckInet():
  10.     print "Checking connection"
  11.     try:
  12.         response = urllib2.urlopen('http://www.ru', timeout = 1)
  13.         print "[SUCCCESS] Internet connection is established"
  14.         return True
  15.     except urllib2.URLError as err:
  16.         pass
  17.         print "[FAILED]Failed to establish the connection"
  18.         return False
  19. def CheckWget():
  20.     print "Checking wget"
  21.     try:
  22.         open ('/usr/bin/wget')
  23.         print "[SUCCCESS] Wget was found"
  24.         return True
  25.     except IOError as err:
  26.         print "[FAILED]Failed to locate wget"
  27.         return False
  28. print "Starting grabVK 2.0"
  29.  
  30. #checking
  31. checkInet = CheckInet()
  32. checkWget = CheckWget()
  33. if checkInet != True:
  34.     exit()
  35. if checkWget != True:
  36.     exit()
  37. print "Checking process finished. Starting downloading"
  38.  
  39. #copying authkey
  40. webbrowser.open_new_tab("http://api.vkontakte.ru/oauth/authorize?client_id=2223684&scope=audio&redirect_uri=http://api.vk.com/blank.html&display=page&response_type=token")
  41. print "Please copy access token from webpage address after authenticating on VK page in your browser"
  42. access_token= raw_input("access_token: ")
  43. print "Please copy expire time from webpage address after authenticating on VK page in your browser"
  44. expires_in = raw_input("expires_in: ")
  45. print "Please copy your id from webpage address after authenticating on VK page in your browser"
  46. user_id = raw_input ("user_id: ")
  47.  
  48. #get playlist
  49. url = "https://api.vkontakte.ru/method/audio.get.xml?uid=" + user_id + "&access_token=" + access_token
  50. page = urllib2.urlopen(url)
  51. html = page.read()
  52. print "[SUCCCESS] Getting playlist"
  53. #creating vars for playlist
  54. artist_list = []
  55. title_list = []
  56. url_list = []
  57. num = 0
  58. #get artists
  59.  
  60. doc  = lxml.html.document_fromstring(html) 
  61. for artist in doc.cssselect('artist'):
  62.     artist_list.append(artist.text)
  63.     num = num + 1
  64. print "[SUCCCESS] Getting artist"
  65. #get titles
Advertisement
Add Comment
Please, Sign In to add comment