Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
python273 committed Jun 22, 2018
1 parent 2f523c2 commit e165e5f
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 30 deletions.
1 change: 1 addition & 0 deletions examples/captcha_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ def main():
# some code
# ...


if __name__ == '__main__':
main()
3 changes: 2 additions & 1 deletion examples/execute_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def main():
vk_session = vk_api.VkApi(login, password)

try:
vk_session.auth()
vk_session.auth(token_only=True)
except vk_api.AuthError as error_msg:
print(error_msg)
return
Expand All @@ -45,5 +45,6 @@ def main():
print(vk_get_filtered(vk, 'wall.get', {'domain': 'durov'}, 'text'))
print(vk_get_filtered(vk, 'groups.get', {'extended': True}, 'name'))


if __name__ == '__main__':
main()
12 changes: 1 addition & 11 deletions examples/get_album_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,7 @@ def main():

vkaudio = VkAudio(vk_session)

albums = []
offset = 0

while True:
temp_albums = vkaudio.get_albums(owner_id='194957739', offset=offset)

if not temp_albums:
break

albums += temp_albums
offset += len(temp_albums)
albums = vkaudio.get_albums(194957739)

print('\nLast 5:')
for album in albums[:5]:
Expand Down
15 changes: 3 additions & 12 deletions examples/get_all_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,8 @@ def main():

artists = collections.Counter()

offset = 0

while True:
audios = vkaudio.get(owner_id=-99463083, offset=offset)

if not audios:
break

for audio in audios:
artists[audio['artist']] += 1

offset += len(audios)
for track in vkaudio.get_iter(-99463083):
artists[track['artist']] += 1

# Составляем рейтинг первых 15
print('\nTop 15:')
Expand All @@ -49,5 +39,6 @@ def main():
for n, track in enumerate(tracks, 1):
print('{}. {} {}'.format(n, track['title'], track['url']))


if __name__ == '__main__':
main()
3 changes: 2 additions & 1 deletion examples/get_full_wall.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def main():
vk_session = vk_api.VkApi(login, password)

try:
vk_session.auth()
vk_session.auth(token_only=True)
except vk_api.AuthError as error_msg:
print(error_msg)
return
Expand Down Expand Up @@ -41,5 +41,6 @@ def main():
if wall['count'] > 1:
print('Last post:', wall['items'][-1])


if __name__ == '__main__':
main()
3 changes: 2 additions & 1 deletion examples/longpoll.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def main():
vk_session = vk_api.VkApi(login, password)

try:
vk_session.auth()
vk_session.auth(token_only=True)
except vk_api.AuthError as error_msg:
print(error_msg)
return
Expand Down Expand Up @@ -61,5 +61,6 @@ def main():
else:
print(event.type, event.raw[1:])


if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion examples/messages_bot/messages_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def main():
vk_session = vk_api.VkApi(login, password)
try:
vk_session.auth()
vk_session.auth(token_only=True)
except vk_api.AuthError as error_msg:
print(error_msg)
return
Expand Down
1 change: 1 addition & 0 deletions examples/proxies_timeout_retries.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ def main():

# ...


if __name__ == '__main__':
main()
3 changes: 2 additions & 1 deletion examples/simple_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def main():
vk_session = vk_api.VkApi(login, password)

try:
vk_session.auth()
vk_session.auth(token_only=True)
except vk_api.AuthError as error_msg:
print(error_msg)
return
Expand All @@ -26,5 +26,6 @@ def main():
if response['items']:
print(response['items'][0])


if __name__ == '__main__':
main()
4 changes: 3 additions & 1 deletion examples/two_factor_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def main():
login, password = 'python@vk.com', 'mypassword'
vk_session = vk_api.VkApi(
login, password,
auth_handler=auth_handler # функция для обработки двухфакторной аутентификации
# функция для обработки двухфакторной аутентификации
auth_handler=auth_handler
)

try:
Expand All @@ -31,5 +32,6 @@ def main():

# ...


if __name__ == '__main__':
main()
3 changes: 2 additions & 1 deletion examples/upload_photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def main():
vk_session = vk_api.VkApi(login, password)

try:
vk_session.auth()
vk_session.auth(token_only=True)
except vk_api.AuthError as error_msg:
print(error_msg)
return
Expand All @@ -31,5 +31,6 @@ def main():

print(photo, '\nLink: ', vk_photo_url)


if __name__ == '__main__':
main()

0 comments on commit e165e5f

Please sign in to comment.