Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
2 changes: 1 addition & 1 deletion fetch_photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def save_photos(urls, directory):
directory = sys.argv[1]
email = raw_input("Email: ")
password = getpass.getpass()
client_id = "2951857" # Vk application ID
client_id = "5152537" # Vk application ID
token, user_id = vk_auth.auth(email, password, client_id, "photos")
albums = get_albums(user_id, token)
print "\n".join("%d. %s" % (num + 1, album["title"]) for num, album in enumerate(albums))
Expand Down
14 changes: 14 additions & 0 deletions vk_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ def auth_user(email, password, client_id, scope, opener):
raise NotImplementedError("Method '%s'" % parser.method)
return response.read(), response.geturl()

#2nd step of authentification
def sms_code(doc, opener):
parser = FormParser()
parser.feed(doc)
parser.close()
parser.params["code"] = raw_input("Type code from SMS: ")
if parser.method == "POST":
response = opener.open("https://m.vk.com" + parser.url, urllib.urlencode(parser.params))
else:
raise NotImplementedError("Method '%s'" % parser.method)
return response.read(), response.geturl()

# Permission request form
def give_access(doc, opener):
parser = FormParser()
Expand All @@ -90,6 +102,8 @@ def give_access(doc, opener):
urllib2.HTTPCookieProcessor(cookielib.CookieJar()),
urllib2.HTTPRedirectHandler())
doc, url = auth_user(email, password, client_id, scope, opener)
if "/login" in urlparse(url).path:
doc, url = sms_code(doc, opener)
if urlparse(url).path != "/blank.html":
# Need to give access to requested scope
url = give_access(doc, opener)
Expand Down