diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/fetch_photos.py b/fetch_photos.py index 38b7267..507a0b5 100755 --- a/fetch_photos.py +++ b/fetch_photos.py @@ -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)) diff --git a/vk_auth.py b/vk_auth.py index 1f09902..e127a30 100644 --- a/vk_auth.py +++ b/vk_auth.py @@ -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() @@ -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)