Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. from userapi import *
  5. import urllib2
  6. import os
  7. import webbrowser
  8.  
  9. USER = "@mail.ru"
  10. PASS = "pass"
  11.  
  12. def getFriendsAvatars(id = None):
  13.     for friend in handler.v_friends(None, id, 0, 60):
  14.         print str(friend.avatar)
  15.         try: os.mkdir("avatars")
  16.         except OSError: pass # directory exists
  17.         if friend.avatar != '0':
  18.             downloadPicture(str(friend.avatar), "avatars", str(friend.id)+".jpg")
  19.            
  20. def downloadPicture(url, pathToDir, title):
  21.     wf = urllib2.build_opener()
  22.     lf = open("avatars/"+title, "wb")
  23.     lf.write(wf.open(url).read())
  24.     lf.close()            
  25.  
  26. try:
  27.     session = Session()
  28.     session.login(USER, PASS)
  29.     handler = UserAPI(session)
  30.     getFriendsAvatars()
  31.     session.logout()
  32.  
  33. except UserAPIError as error:
  34.     print "Get code: " + str(error.code) + " " + error.text
  35.  
  36. except JSONProblemError as error:
  37.     print "JSON data is a bullshit, storing to disk"
  38.     f = file('bs', 'w')
  39.     f.write(error.json_data)
  40.     f.write("\n\n\n" + str(error.supplement))
  41.     f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement